user2604504
user2604504

Reputation: 717

Matlab not recognizing string variable

I have a variable that is holding a string (the string contains a path to a .mat file). However whenever I call load the variable I get an error saying "Error using load Unable to read file"

Here is my code where I call load:

fName = strcat(fName,'_features.mat');
display(fName);
load(fName);

For those curious fName = '/Users/MATLAB/10360453085_p2_features.mat'

Why am getting an error on load even though when I copy the value of fName into load it works perfectly fine, but using load(fName) gives me an error?

Upvotes: 1

Views: 354

Answers (1)

Jonas
Jonas

Reputation: 74940

Most likely, fname is initialized somewhere as a cell array. strcat will therefore return a cell array, so that disp will display it as 'name' rather than name.

load(fName{1}) 

or

load(char(fName))

will work in this case.

Upvotes: 1

Related Questions