matlab去掉零元素
方法1:
a = [0,1,2,0,19,3,0,0];
b = a(find(a));
方法2:
a =[13 0 5];
>> a(a>0)
ans =
13 5
方法3:
[Matlab] 去除矩陣內的0元素
向量:
>> a=[1,0,2,3,0,4,5]
a =
1 0 2 3 0 4 5
>> a(find(a==0))=[]
a =
1 2 3 4 5
矩陣:
>> a=[0 0;1 2;0 0;3 4]
a =
0 0
1 2
0 0
3 4
>> a(find(a==0))=[]
a =
1 3 2 4
>> a=reshape(a,2,2)
a =
1 2
3 4
>> a=[1,0,2,3,0,4,5]
a =
1 0 2 3 0 4 5
>> a(find(a==0))=[]
a =
1 2 3 4 5
矩陣:
>> a=[0 0;1 2;0 0;3 4]
a =
0 0
1 2
0 0
3 4
>> a(find(a==0))=[]
a =
1 3 2 4
>> a=reshape(a,2,2)
a =
1 2
3 4