Extracting zeros from vectors

4 Ansichten (letzte 30 Tage)
IBM watson
IBM watson am 24 Okt. 2018
Kommentiert: madhan ravi am 24 Okt. 2018
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]

Akzeptierte Antwort

madhan ravi
madhan ravi am 24 Okt. 2018
Bearbeitet: madhan ravi am 24 Okt. 2018
>> 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 Kommentar
madhan ravi
madhan ravi am 24 Okt. 2018
if this is not what you are looking for let know

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Andrei Bobrov
Andrei Bobrov am 24 Okt. 2018
S1 = S(S ~= 0)

Kategorien

Mehr zu Modeling finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by