Reading multiple .dat files into MatLab -
i having great difficulties reading bunch of .dat files matlab. have tried google problem, after 1 hour still can't code work. in total have 141 .dat files. each file consist of 3 lines of header information (which not want include), , bunch of rows, each 3 columns of numbers. want merge rows .dat files 1 large matrix featuring rows, , 3 columns (since each row in .dat files contains 3 numbers). code have attempted use:
d = dir('c:\users\kristian\documents\matlab\polygoner1\'); out = []; n_files = numel(d); = 3:n_files fid = fopen(d(i).name,'r'); data = textscan(fid,'%f%f%f','headerlines',3); out = [out; data]; end
however, when try run code error message
??? error using ==> textscan invalid file identifier. use fopen generate valid file identifier. error in ==> readpoly @ 6 data = textscan(fid,'%f%f%f','headerlines',3);
if knows how can work, extremely grateful!
the problem when use fopen
, not giving full path of file
path = 'c:\users\kristian\documents\matlab\polygoner1\' d = dir(path); .... %as @craigim advised it, otherwise can use strcat my_file = fullfile(path, {d.name}) = 3:n_files fid = fopen(my_file{i},'r'); .... fclose(fid); end
Comments
Post a Comment