erasing particular rows of a vector
1 回表示 (過去 30 日間)
古いコメントを表示
Dear all,
I have
A=[
0;
2;
34;
45
0;
12;
23;
12;
0;
23]
and I want to erase the rows that contain zero and the element that follows immediately after zero
So I want to erase the elements [0,2], [0,12] and [0,23]
Note that zeros can appear anywhere in the vector. The above vector is a simple example
thanks
0 件のコメント
採用された回答
Wayne King
2012 年 8 月 1 日
indices = find(A==0);
indices = [indices; indices+1]
A(indices) = [];
0 件のコメント
その他の回答 (1 件)
Albert Yam
2012 年 8 月 1 日
Look for the index of the elements that are zero. That is to say 'find' them. Once you have them, you know that those index '+1', are the rows that follow. Then remove them (all at once, or backwards).
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!