how to update a variable in a .mat file for matlab?

8.9k Views Asked by At

I have a matlab .mat file that stores a bunch of variables. How do I update a single variable?

I tried doing this:

load('filename.mat');
variable='Test';
save('filename.mat',variable);

but it says

??? Error using ==> save
Variable 'C:\' not found.

What does this mean and how can I fix it?

Thank you!

2

There are 2 best solutions below

0
On BEST ANSWER

I think you are looking for the "-append" option:

save('filename.mat','-append');

From http://www.mathworks.com/help/techdoc/ref/save.html

For MAT-files, -append adds new variables to the file or replaces the saved values of existing variables with values in the workspace.

1
On

To save an individual variable to a .mat file, you need to quote its name:

save('filename.mat','variable');

See http://www.mathworks.co.uk/help/techdoc/ref/save.html.