Extracting zeros from vectors

4 ビュー (過去 30 日間)
IBM watson
IBM watson 2018 年 10 月 24 日
コメント済み: madhan ravi 2018 年 10 月 24 日
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]

採用された回答

madhan ravi
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 件のコメント
madhan ravi
madhan ravi 2018 年 10 月 24 日
if this is not what you are looking for let know

サインインしてコメントする。

その他の回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2018 年 10 月 24 日
S1 = S(S ~= 0)

カテゴリ

Help Center および File ExchangeModeling についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by