简体   繁体   English

matlab中如何判断一个矩阵是否为空?

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

In my matlab program, I want to determine whether a variable or output of a function is empty or not, before going further.在我的 matlab 程序中,在继续之前,我想确定 function 的变量或 output 是否为空。

Actually, I've written a function which calculates an intersection point between two line segments.实际上,我写了一个 function 来计算两条线段之间的交点。 if there is no intersection, the function returns nothing (so the variable assigned by the function will be empty matrix).如果没有交集,则 function 不返回任何内容(因此 function 分配的变量将为空矩阵)。

I know I could use size function but is there any better way to do that?我知道我可以使用size function 但有更好的方法吗?

You can use isempty .您可以使用isempty For instance:例如:

>> isempty([])

ans =
     1

>> isempty([42])

ans =
     0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM