avoid zero value from vector

4 次查看(过去 30 天)
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.

采纳的回答

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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by