在 MATLAB 中檢查陣列或矩陣是否為空
Sheeraz Gul
2022年5月11日
一個簡單的空矩陣是維度為 0 x 0
的矩陣。維度為 0 x n
和 n 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 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