1

I'm trying to get the Save/Load command to use a variable as the path in octave/matlab I can save variables using the Save/Load command

save('/tmp/a1_var.mat','V1','V2')

But the path I use will change based on the location of the file. How can I have the save/load command accept variables for the path/and or filename?

Example:

dirpath='/tmp/';
save(dirpath,'a1_var.mat','V1','V2')

I tried

save(strcat(dirpath),'a1_var.mat','V1','V2')

but I get an error save: unable to open output file

1
  • 2
    Tried save(strcat(dirpath,'a1_var.mat'),'V1','V2')? I think fullfile might be safer instead of strcat. Commented Jun 3, 2014 at 13:09

1 Answer 1

1

The input to save is comma separated so your command

save(dirpath,'a1_var.mat','V1','V2')

is trying to save a variable called 'a1_var.mat' as this is after the first comma. The error message is because you have defined the filename as just the folder '/tmp/' rather than a file.

You need to group your pathname and filename into one string using square brackets []

save([dirpath,'a1_var.mat'],'V1','V2')
Sign up to request clarification or add additional context in comments.

Comments

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.