1

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!

Shai
  • 111,146
  • 38
  • 238
  • 371
O_O
  • 4,397
  • 18
  • 54
  • 69
  • `load` loads all variables in the .mat file into the current workspace, so you shouldn't need to specify which variables to save should you? – slugonamission Nov 08 '11 at 00:45

2 Answers2

8

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.

stardt
  • 1,179
  • 1
  • 9
  • 14
-1

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.

Oliver Charlesworth
  • 267,707
  • 33
  • 569
  • 680
  • 5
    doesn't this create a file with only 'variable' in it? If there are other variables in the file, they will be lost. – stardt Nov 08 '11 at 01:27