Checking empty matrix in Octave

There are times when I want to check whether a certain variable results in empty matrix or not. This can be done in several ways. One of the easiest is to check the length of the variable. If it returns zero than it is an empty matrix.

octave:\> a=ones(0,3); %create empty matrix
octave:\> if(length(a)==0)
> disp('It iss empty matrix');
> end

other function that will return zero on an empty matrix includes:

A = [];
size(A), length(A), numel(A), any(A), sum(A)

for more info check this page on Mathworks.

Advertisements

One Response

  1. nice idea.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: