textscan desnt work in forloop

okay so this is the coad, the text scan fuction works and the whole coad runs without the for loops, but when addiing the forloops the coad doesn work the error i m getting is :
Error using textscan
Invalid file identifier. Use fopen to generate a valid file identifier.
Error in forllooptest (line 7)
c = textscan(fid,'%f %f %f %f %f %f %f','HeaderLines', 12);
for i = 0
for j = 0
for k = 0
for l = 0:8
b = sprintf('cl%d%d%d%d.txt',i,j,k,l);
fid = fopen(b);
c = textscan(fid,'%f %f %f %f %f %f %f','HeaderLines', 12);
fclose(fid);
%delete(cl.txt);
% Separate boundary points
d = c{:,3}(1,:);
%if (exist(saveFlnmAF,'file'))
%delete(saveFlnmAF);
%end
g(i) = d
[val, idx] = maxk(g,5)
end
end
end
end
Please does someone know how to correct this. thank you

9 件のコメント

KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 11 月 16 日
Is this complete code?
Divya Patel
Divya Patel 2019 年 11 月 16 日
Yes sir!, What am I missing,
Divya Patel
Divya Patel 2019 年 11 月 16 日
idk what seems to be the problem with textscan or is it the for loop?
Divya Patel
Divya Patel 2019 年 11 月 16 日
XFOIL Version 6.99
Calculated polar for: NACA 0001
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.0001 0.00531 0.00015 0.0000 1.0000 1.0000
0.000 -0.0001 0.00531 0.00015 0.0000 1.0000 1.0000
0.000 -0.0001 0.00531 0.00015 0.0000 1.0000 1.0000
here is the file..file name cl0001.txt..and so one to cl0008.txt
per isakson
per isakson 2019 年 11 月 16 日
Does cl0000.txt exist?
Divya Patel
Divya Patel 2019 年 11 月 16 日
Ohh...let me check if that works..it doesn't exist!!!
Divya Patel
Divya Patel 2019 年 11 月 16 日
Thank you the whole issue is resolved. I was just stupid to not see that!
Divya Patel
Divya Patel 2019 年 11 月 16 日
i have a follow up question!, how would i tell it to skip that fild read if the line is empty, for textscan so it donest give me that error!
Walter Roberson
Walter Roberson 2019 年 11 月 19 日
if fid < 0; continue; end

サインインしてコメントする。

回答 (1 件)

Raunak Gupta
Raunak Gupta 2019 年 11 月 19 日

0 投票

Hi,
Hope the file identifier error is resolved. For the follow up question you may read the file from textscan even if it is empty and then can check if the resultant cell array is empty or not. If it is empty, then you may simply skip that iteration in the loop.
For checking if the cell array is fully empty you may use following
number = sum(cellfun(@isempty,c) == 1)
This number should be zero for fully empty text file.

カテゴリ

ヘルプ センター および File ExchangeConstruct and Work with Object Arrays についてさらに検索

タグ

質問済み:

2019 年 11 月 16 日

コメント済み:

2019 年 11 月 19 日

Community Treasure Hunt

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

Start Hunting!

Translated by