Filter löschen
Filter löschen

avoid zero value from vector

4 Ansichten (letzte 30 Tage)
Israt Jahan
Israt Jahan am 22 Nov. 2016
Beantwortet: Stephen23 am 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.

Akzeptierte Antwort

Stephen23
Stephen23 am 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

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing 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