Two textscan stamentents for the same file in coad

1 view (last 30 days)
I am using two different textscan statements with deffrent vareables, why can't it store the same file in two diffrent cells or variables. anyone know how to do this?
here is the coad
i = 7;
b = sprintf('cl%d.txt',i);
fid1 = fopen(b);
e = textscan(fid1,'%q','HeaderLines', 3);
c = textscan(fid1,'%f %f %f %f %f %f %f','HeaderLines', 12);
fclose(fid1);
h = e{1,1}{5,:}
d = c{:,3}(1,:)
and the error :-
Index in position 1 exceeds array bounds.
Error in nacanumbertest (line 11)
d = c{:,3}(1,:)
this is the .txt file for refrence.
XFOIL Version 6.99
Calculated polar for: NACA 0007
1 1 Reynolds number fixed Mach number fixed
xtrf = 1.000 (top) 1.000 (bottom)
Mach = 0.000 Re = 0.271 e 6 Ncrit = 9.000
alpha CL CD CDp CM Top_Xtr Bot_Xtr
------ -------- --------- --------- -------- -------- --------
0.000 -0.0000 0.00674 0.00218 -0.0000 1.0000 1.0000
0.000 -0.0000 0.00674 0.00218 -0.0000 1.0000 1.0000
0.000 -0.0000 0.00674 0.00218 -0.0000 1.0000 1.0000

Answers (1)

Walter Roberson
Walter Roberson on 16 Nov 2019
e = textscan(fid1,'%q','HeaderLines', 3);
%q is quoted string format. There is nothing that it cannot match, other than end of file, so in the form given it will consume up to the end of file.
c = textscan(fid1,'%f %f %f %f %f %f %f','HeaderLines', 12);
That is picking up from end of file, but there is nothing left in the file to consume.
I suspect you want an frewind(fid1) before the second textscan. But better would be to pass in a format repetition count after '%q' and before 'Headerlines' to tell textscan how many of those %q to process. Remember that %q is whitespace delimited except inside double-quotes, and skips leading whitespace, so you have to be careful on your counting. Once you have the count correct, your second textscan would have a reduced HeaderLines because you would already be positioned part way into the file.

Categories

Find more on Large Files and Big Data in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!