How to jump to first loop if nest for loop need to terminate due to condition

조회 수: 2 (최근 30일)
I am using nested for loops as below, (i) is number of files read and (j) is tline=fgetl(fid). when tline return -1 fprintf give error. when tline in j loop return -1 I want to jump to i loop to read next file and overpass the error in j loop.
for i=1:10
for j=1:100
%code
tline=fgetl(fid)
fprintf(fid,tline)
end
end

채택된 답변

David Hill
David Hill 2022년 8월 17일
for i=1:10
for j=1:100
%code
tline=fgetl(fid)
if tline==-1
break;
end
fprintf(fid,tline)
end
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by