Question on the use of function 'load' to open a *.mat file

1 view (last 30 days)
I have multiple *.mat files. So the filename is generated in a loop as below:
File = ['hb', num2str(A(i)), '.mat'];
When I tried to load it by doing:
load File;
I got the below error:
Error using load
Unable to read file 'File': no such file or directory.
Error in Combine_matfiles (line 17)
load File;
I am 100% sure the generated filename, File is correct, and the file is right there in the same directory. I can open it by typing load with the file name in the command window without any problem.
What did I do wrong? Thanks.

Accepted Answer

James Tursa
James Tursa on 27 Nov 2013
Edited: James Tursa on 27 Nov 2013
The statement:
load File
is equivalent to:
load('File')
What you want to do is
load(File)
This is a general MATLAB behavior for calling functions without using parentheses, not specific to just the load function. E.g., in general
myfunction thisinput thatinput
is equivalent to
myfunction('thisinput','thatinput')

More Answers (0)

Categories

Find more on File Operations in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!