how to extract special elements from a matrix
显示 更早的评论
Hi, I have a matrix, let say M1 = [1,0,0,8;0,0,15,0;0,0,0,0;7,0,0,0].
How can I extract only non-zero elements to another matrix M2.
Thank you.
回答(2 个)
Andrei Bobrov
2012-10-13
M2 = nonzeros(M1);
Walter Roberson
2012-10-13
M2 = M1(M1 ~= 0);
类别
在 帮助中心 和 File Exchange 中查找有关 Aerospace Blockset 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!