MATLAB loads file it cannot find
Show older comments
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?
Accepted Answer
More Answers (2)
KSSV
on 14 Oct 2016
0 votes
Use exist to find out whether file exists... doc exist
Image Analyst
on 14 Oct 2016
Edited: Image Analyst
on 14 Oct 2016
0 votes
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.
Categories
Find more on File Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!