MATLAB Answers



Asked by AP
on 9 Jun 2011

How can I save variables that is used inside a function? Can I somehow use SAVE command that save the local variables of a function without specifying their name? Something like SAVE ALL.


Log in to comment.


1 Answer

Paulo Silva
Answer by Paulo Silva
on 9 Jun 2011

To save all the variables that are inside the function to the file MyFunVariables.mat in the current directory do this


or this

save 'MyFunVariables.mat'

The code must be inside the function!

  1 Comment

Loginatorist on 9 Jun 2011

Not only must the code Paulo gives be in the function, but it should appear in a location within the function where the variables of interest are defined. For example, as the last line in the main function (before the subfunctions, if any).
If, for example, the code was placed as the first line of the function, the only things saved would be the input arguments.

Log in to comment.

Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!