remove the zeros in the Matrix

3 次查看(过去 30 天)
How can I remove the zeros from matrix A ??

采纳的回答

Adam Danz
Adam Danz 2021-11-19
编辑:Adam Danz 2021-11-19
Here's how to remove rows or columns that contain only 0s
data = [0 0 0 0; 0 4 5 2; 0 2 5 4; 0 2 4 1]
data = 4×4
0 0 0 0 0 4 5 2 0 2 5 4 0 2 4 1
rowsAll0 = all(data==0,1); % columns of 0s
data(:, rowsAll0) = [];
colsAll0 = all(data==0,2); % rows of 0s
data(colsAll0, :) = []
data = 3×3
4 5 2 2 5 4 2 4 1

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品


版本

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by