MATLAB: How to find undefined matrix in a code

defined and undefined matrixif statementmatrix

Hello everyone, i have a matrix that presents the alarmed devices in the coverage of an access point , but i dont have alarmed devices for all access point covarege area, and you know at that time the matrix for alarm is undefined, totally empty matrix so i can't use it in the following steps. What i am asking is : is there any way to write an if statement saying if that matrix is defined do that, if it is undefined do another thing. Can you help me please?

Best Answer

If the variable is not defined at all, you can use this:
if( exist('variable_name','var') )
% variable_name is defined
else
% variable_name is not defined
end
If the variable is in fact defined but is actually empty, do this instead:
if( isempty(variable_name) )
% variable_name is empty
else
% variable_name is not empty
end