I am working with a 1627x11 array, labelled A, and I want to delete the entries that have 0 in the 9th column (i.e delete the whole row).
V = A(:,9);
vals=find(V==0);
A(vals)=[ ];
after running that code, the array converts to an 1x16617 double - which is not wat I anticipated nor want.
To reiterate, the 9th column which has a sort of counter is used to keep track of which point I am working with, and I do not want to include the rows which are in the 0th point.
Rows 0 to 1280 contains 0 in the 9th column (this was done by observing the array), so I should have a 347x11 array after running the code.
What am I doing wrong

 채택된 답변

Brian Hart
Brian Hart 2019년 1월 29일

1 개 추천

Hi Ramitha,
You almost got it. For your last line of code, try
A(vals,:)=[];
The way you tried it at first uses linear lindexing (see sub2ind)

댓글 수: 3

Hans123
Hans123 2019년 1월 29일
Thanks Brian, ti worked perfectly!
Stephen23
Stephen23 2019년 1월 30일
Simpler and more efficient to use logical indexing (without find):
A(A(:,9)==0,:) = [];
Hans123
Hans123 2019년 1월 30일
that's great! Thanks Stephen

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

madhan ravi
madhan ravi 2019년 1월 29일
편집: madhan ravi 2019년 1월 30일

0 개 추천

A(~any(A(:,9),2),:)=[]

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

제품

릴리스

R2017b

질문:

2019년 1월 29일

댓글:

2019년 1월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by