MATLAB: How to check if a matrix has already been created

MATLABmatricesmatrixvariables

I have a function that will be looped through as the functions call each other i.e. function1->function2->function3->function1 etc.
In one of these functions I want to create a matrix that will store a variable for comparison, however this matrix should be retained during all cycles of the program therefore I only want to create this matrix once.
See pseudocode below for what I want to achieve.
if(exist matrix == false)
%create matrix
else
%do nothing
The use of this is to store an improvement value for splitting a data set. See below:
if(improvementValue > improvementStorage(1,1))
improvementStorage(1,1)= improvementValue;
end
(improvementStorage being the matrix I want to create on the first iteration only.)
Any help on how to create this matrix once and not overwriting it with each program iteration would be appreciated.

Best Answer

You can either define a variable which is included in the inputs and outputs of all functions. Then you have full control from anywhere.
Or you can use a persistent variable in one function:
function out = myFunc(In)
persistent M
if isempty(M)
disp('M is not initialized');
end
M = rand(2);
end