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?
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.
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.
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.
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.
You can use isempty
. For instance:
>> isempty([])
ans =
1
>> isempty([42])
ans =
0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With