I want to remove zeroes from an array. The array more zero per row. For example: a = [200.03 303.56 0 0 0; 155.23 0 0] Should be turned into a = [200.03 303.56; 155.23]

1 次查看(过去 30 天)
I want to remove zeroes from an array. The array has exactly mote zero per row. For example:
a = [1 4 3 0 0 0; 1 5 0 0 0; 1 8 1 0 0; 5 4 4 0 0;1 5 2 0 0]
Should be turned into
a = [1 4 3; 1 5 5; 1 8 1; 5 4 4; 1

回答(1 个)

KSSV
KSSV 2018-3-14
a = [1 4 3 0 0 0 1 5 0 0 0 1 8 1 0 0 5 4 4 0 0 1 5 2 0 0]
% b = [1 4 3 1 5 5 1 8 1 5 4 4 1 ] ;
b = a ;
b(a==0) = [] % remove zeros
b = a ;
b(b~=0) % pick non zeroes

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by