textscan desnt work in forloop

조회 수: 9 (최근 30일)
Divya Patel
Divya Patel 2019년 11월 16일
댓글: Walter Roberson 2019년 11월 19일
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
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일
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.

카테고리

Help CenterFile Exchange에서 Construct and Work with Object Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by