1

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?

7
  • 1
    What is the value of fName, before execution of strcat? Commented Feb 10, 2014 at 5:49
  • It comes from an array that contains a list of paths. The array is declared as follows: imnames = {} Commented Feb 10, 2014 at 6:07
  • 2
    I ask because you use fName to create an fName. Are you sure that value of fName before strcat is correct? Commented Feb 10, 2014 at 6:26
  • @user2604504: can you tell us the exact error message? Commented Feb 10, 2014 at 8:33
  • He does display it and says it's correct. Isn't there a drive letter missing though? Then again, in that case, manually copying the value into load shouldn't work either. Commented Feb 10, 2014 at 9:17

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

That wouldn't create a "Unable to read file" error though - as far as I know.
@Sebastian: yes, you're right. There may be multiple problems here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.