I'd like to skip the file that's not there and bring it up!
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaire
Stephen23
le 19 Mar 2023
Modifié(e) : Stephen23
le 20 Mar 2023
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
Réponse acceptée
John D'Errico
le 17 Mar 2023
Modifié(e) : John D'Errico
le 17 Mar 2023
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 commentaires
John D'Errico
le 19 Mar 2023
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.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Introduction to Installation and Licensing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!