I have a for loop that used to open text files for plotting, and I want to have an if else statement that will set headerlines equal to 5 for test files having less than 500 rows, and headerlines equal to 400 for those having in excess of 500 rows. I have this so far but it does not seem to be working;
for k = 58:212inputFileName = sprintf('MT_%05i-000.txt',k); outputFileName = sprintf('results%05i.tiff',k); fid = fopen(inputFileName); newcmd=sprintf('more %s|wc -l', inputFileName); [p,num_lines]=system(newcmd); if num_lines<=500 datacell = 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','HeaderLines',5); fclose(fid); else datacell = 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','HeaderLines',500); fclose(fid); %number of %f reflects number of columns to record from text file
end
Best Answer