Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine whether a matrix is empty or not in matlab?

Tags:

matlab

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?

like image 857
Kamran Bigdely Avatar asked Mar 23 '09 17:03

Kamran Bigdely


People also ask

How do you check if a matrix is not empty?

To check if an array is empty or not, you can use the . length property. The length property sets or returns the number of elements in an array. By knowing the number of elements in the array, you can tell if it is empty or not.

How define empty in MATLAB?

A = ClassName. empty( sizeVector ) returns an empty array with the specified dimensions. At least one of the dimensions must be 0. Use this syntax to define an empty array that is the same size as an existing empty array.

How do you check if a matrix is in MATLAB?

Description. TF = ismatrix( A ) returns logical 1 ( true ) if A is a matrix. Otherwise, it returns logical 0 ( false ). A matrix is a two-dimensional array that has a size of m-by-n, where m and n are nonnegative integers.

Is empty cell MATLAB?

isempty (MATLAB Functions) tf = isempty(A) returns logical true ( 1 ) if A is an empty array and logical false ( 0 ) otherwise. An empty array has at least one dimension of size zero, for example, 0-by-0 or 0-by-5.


1 Answers

You can use isempty. For instance:

>> isempty([])

ans =
     1

>> isempty([42])

ans =
     0
like image 89
MatlabDoug Avatar answered Sep 17 '22 22:09

MatlabDoug