フィルターのクリア

avoid zero value from vector

4 ビュー (過去 30 日間)
Israt Jahan
Israt Jahan 2016 年 11 月 22 日
回答済み: Stephen23 2016 年 11 月 22 日
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 Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by