MATLAB loads file it cannot find
Mostrar comentarios más antiguos
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?
Respuesta aceptada
Más respuestas (2)
KSSV
el 14 de Oct. de 2016
0 votos
Use exist to find out whether file exists... doc exist
Image Analyst
el 14 de Oct. de 2016
Editada: Image Analyst
el 14 de Oct. de 2016
0 votos
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.
Categorías
Más información sobre File Operations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!