MATLAB loads file it cannot find
Mostra commenti meno recenti
I want to load a file, and see whether another, related, file exists in the folder. This all happens in a function. The function is called in a script, where the folder where the files are is added to the path. So in this function, I do something like:
if isempty(dir([filename '_extension.mat']))==0
load([filename '_extension.mat']);
else
% code to create such a file
end
To my surprise, the loading works fine, but it does not find the other file in the folder (which does exist). Upon checking, I find that
load(filename);
works fine, but
dir(filename);
gives the error that the file is not found.
How is it possible, that MATLAB can load a file that it cannot find?
Risposta accettata
Più risposte (2)
KSSV
il 14 Ott 2016
0 voti
Use exist to find out whether file exists... doc exist
Image Analyst
il 14 Ott 2016
Modificato: Image Analyst
il 14 Ott 2016
0 voti
See code in the FAQ to load/process multiple files: http://matlab.wikia.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F
When I try your code with a nonexistent filename, it does not step to the load() statement.
Categorie
Scopri di più su File Operations in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!