try catch loop to evaluate what contains in the folder

조회 수: 3 (최근 30일)
ayman mounir
ayman mounir 2019년 8월 9일
편집: Adam Danz 2019년 8월 13일
If I have a function evaluate the files exist in the directory. I want if there is an error in evaluation of one first file go to the next file and evaulate it until all the files are evaluated. simlpy try and catch loop.
for example:
for i=number of files
try
eval.fun(file(i))
catch ME
sprintf( ' error in %s', file.name(i))
end
end
  댓글 수: 6
Stephen23
Stephen23 2019년 8월 9일
편집: Stephen23 2019년 8월 9일
"this should try to perform the code for file(1) if error happens then perform the code for file(2) until the last file i have uploaded"
I doubt it. You do not define file anywhere in your code, but if it is some kind of array of filenames then your code won't do anything like what you state, for the reasons that I have already explained in my previous comments. Perhaps you should read the MATLAB documentation links that I gave you.
Without knowing what load_files and file are, we have no idea what your code does.

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2019년 8월 13일
evaluction=eval(file(1)))
We do not know what the data type is of file, but in all of the cases that come to mind, eval() does not return a value.
Also I suspect that file might be file names, in which case you are more likely to need file{i}

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by