I use textscan to import txt files mixed with string and numbers. Usually these files have 50 columns. The first line is the header. I can make the string column the last column in the data file. My code is below. Now the data files vary in column numbers. I can check the tokens size for the column numbers. But I don't know how to make my text scan more flexible to handle variable column sizes.
fid = fopen(filename,'rt');tline = fgetl(fid);tokens = regexp(strtrim(tline), ',', 'split');a = textscan(fid,'%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%q','Delimiter',',','EmptyValue',NaN); fclose(fid);
Thank you, Jane
Best Answer