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

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.

 Respuesta aceptada

James Tursa
James Tursa el 27 de Nov. de 2013
Editada: James Tursa el 27 de Nov. de 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')

Más respuestas (0)

Categorías

Etiquetas

Preguntada:

el 27 de Nov. de 2013

Comentada:

el 27 de Nov. de 2013

Community Treasure Hunt

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

Start Hunting!

Translated by