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

O_O picture O_O · Nov 8, 2011 · Viewed 7.5k times · Source

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!

Answer

stardt picture stardt · Nov 8, 2011

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.