Saving variables within a function? (MATLAB)

2.8k views Asked by At

I have a function that goes something like this:

function [] = function1

-variable1= value1; -variable2= value2;

-matrix1=[] -matrix2=[]

-loops that fill in matrix1 and matrix2

-more declarations

-final function1 end

function2[] takes values from function 1 and does stuff, creates new variables funcion2 end

function3[] that uses values from function 2 and function4[] that uses function 3.

(Sorry for all of that by the way). Now, my question is, is there anyway to save variables, arrays, etc. in the workspace for later analysis? All 4 functions are on the same tab in the MATLAB editor.

1

There are 1 answers

0
NeelC On

To save any particular variable from workspace in Matlab you should execute the following

save('Name of the mat file','Name of the variable')

To save multiple variable the command shall be

save('name of the mat file','var1','var2'...)

variable can be array, matrix, structure, double anything. For any other use of the function save please docsearch it in the command prompt