tags:

views:

2504

answers:

2

In my matlab program, I want to determine whether a variable or output of a function is empty or not, before going further.

Actually, I've written a function which calculates an intersection point between two line segments. if there is no intersection, the function returns nothing (so the variable assigned by the function will be empty matrix).

I know I could use size function but is there any better way to do that?

+14  A: 
>> isempty([])

ans =

     1

>> isempty([42])

ans =

     0
MatlabDoug
+1  A: 

there is a function :

isempty()

you can use it. the code will be something like this:

a=[your matrix];
if isempty(a) then
  disp('it is empty');
else
  disp('it is not empty');
end
There's no need to post redundant answers. Doug's answer already covered this.
gnovice

related questions