erasing particular rows of a vector
조회 수: 4(최근 30일)
표시 이전 댓글
Sabbas 2012년 8월 1일
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
Wayne King 2012년 8월 1일
indices = find(A==0);
indices = [indices; indices+1]
A(indices) = ;
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).
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!