在 MATLAB 中检查数组或矩阵是否为空

Sheeraz Gul 2022年5月11日
在 MATLAB 中检查数组或矩阵是否为空

一个简单的空矩阵是维度为 0 x 0 的矩阵。维度为 0 x nn x 0 的矩阵也是空的。

本教程演示如何使用 isempty() 检查数组或矩阵是否为空。

在 MATLAB 中使用 isempty() 确定数组或矩阵是否为空

isempty() 方法检查矩阵或数组是否为空。如果数组为空,它将返回 1 为真,否则返回 0 为假。

例子:

A = [1, 2, 3];
B= [];
C = rand(2,2,2);
D = [1 3 5; 2 4 6; 7 8 10];
D(:,:,:) = []; %% Deleting the members of D matrix

disp('The Result for array A is: '); disp(isempty(A))
disp('The Result for array B is: '); disp(isempty(B))
disp('The Result for Matrix C is: '); disp(isempty(C))
disp('The Result for Matrix D is: '); disp(isempty(D))

输出:

The Result for array A is: 
     0

The Result for array B is: 
     1

The Result for Matrix C is: 
     0

The Result for Matrix D is: 
     1
作者: Sheeraz Gul
Sheeraz Gul avatar Sheeraz Gul avatar

Sheeraz is a Doctorate fellow in Computer Science at Northwestern Polytechnical University, Xian, China. He has 7 years of Software Development experience in AI, Web, Database, and Desktop technologies. He writes tutorials in Java, PHP, Python, GoLang, R, etc., to help beginners learn the field of Computer Science.

LinkedIn Facebook

相关文章 - MATLAB Array

相关文章 - MATLAB Matrix