How to remove zero values from vector?
2 ビュー (過去 30 日間)
古いコメントを表示
Hi,
Let's say I have vector something like:
q = [0 0 0 2 4 10 9 5 0 0 0 8 9]
I want it to be something like:
q = {0 0 0 2 4 10 9 5 8 9]
How can I choose to remove the zero values but without removing the first three zeroes?
Thank you.
0 件のコメント
採用された回答
Andrei Bobrov
2013 年 6 月 14 日
q = [0 0 0 2 4 10 9 5 0 0 0 8 9];
out = [q(1:find(q~=0,1,'first')-1) q(q~=0)];
0 件のコメント
その他の回答 (2 件)
belairaway
2017 年 5 月 9 日
編集済み: belairaway
2017 年 5 月 9 日
I think that using the built-in function nonzeros is better
0 件のコメント
Azzi Abdelmalek
2013 年 6 月 14 日
編集済み: Azzi Abdelmalek
2013 年 6 月 14 日
q = [0 0 0 2 4 10 9 5 0 0 0 8 9];
out=[q(1:find(q~=0,1)) q(q~=0)]
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Get Started with MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!