I'd like to skip the file that's not there and bring it up!
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello, I am a student who is learning mat rap. I left a question because I didn't know something while doing the assignment.
The codes I have to sing are NO_001, NO_002,...Code up to NO_100.
There is a missing number among the 100 numbers.
I want to keep the for statement except for this missing file, but I don't know what function to put in it.
clc; clear;
for k=1:100
load(['01__input/NO_',num2str(k,'%03d'),'.mat'],'data')
if isempty( )
continue
end
end
댓글 수: 1
Stephen23
2023년 3월 19일
편집: Stephen23
2023년 3월 20일
A simple alternative approach is to use DIR, then you can simply avoid the problem:
S = dir('01__input/NO_*.mat');:
for k = 1:numel(S)
F = fullfile(S(k).folder,S(k).name);
D = load(F,'data');
.. do whatever with D.data, or store for later processing:
S(k).data = D.data;
end
채택된 답변
John D'Errico
2023년 3월 17일
편집: John D'Errico
2023년 3월 17일
mat rap? Is that some godawful new song I've never heard before? ;-) That just seems, well, raprehensible to me.
You don't want to use isempty there. Instead, use the exist function. Test to see if the file exists, BEFORE you try to load the file. If it does not exist, then do you want to try load it in the first place?
댓글 수: 2
John D'Errico
2023년 3월 19일
Why is it every older generation never seems to undertand the music of today, regardless of what generation we are in? Let me ask MATLAB...
why
Gosh, I'm not sure that explains anything. Darn computers.
Anyway, I had to laugh a little. But MATLAB does not understand rap either. For example,
help rapmat
It does try. But it gets confused. :)
Anyway, have a nice day. I'm happy to have made you smile.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!