matlabsavematlab-load

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


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!


Solution

  • 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.