Azzera filtri
Azzera filtri

avoid zero value from vector

4 visualizzazioni (ultimi 30 giorni)
Israt Jahan
Israt Jahan il 22 Nov 2016
Risposto: Stephen23 il 22 Nov 2016
Hi I have got two vectors from running my matlab code such as
x=[5 0 9 0 4 0 7 0]
y=[0 9 0 7 0 2 0 6]
now i want to use these two vector as input in other code. so i need to avoid these zero values from above vector and my input will be like
x=[5 9 4 7]
y=[9 7 2 6]
would anyone help me to how can write the matlab code to get above vectors.

Risposta accettata

Stephen23
Stephen23 il 22 Nov 2016
Simply use logical indexing:
>> x =[5 0 9 0 4 0 7 0];
>> xnew = x(x~=0)
xnew =
5 9 4 7

Più risposte (0)

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by