Extracting zeros from vectors
3 次查看(过去 30 天)
显示 更早的评论
I need to extract zeros from a vector while keeping the same order of elements in s.
Like this :
S=[1 0 0 2 3 0 0 0 2 1 0 4 0 0 0 0 1 0 2]
S1=[1 2 3 2 1 4 1 2]
0 个评论
采纳的回答
madhan ravi
2018-10-24
编辑:madhan ravi
2018-10-24
>> S=[1 0 0 2 3 0 0 0 2 1 0 4 0 0 0 0 1 0 2]
S =nonzeros(S)'
S =
Columns 1 through 13
1 0 0 2 3 0 0 0 2 1 0 4 0
Columns 14 through 19
0 0 0 1 0 2
S =
1 2 3 2 1 4 1 2
>>
更多回答(1 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!