Find and remove a value from an array

조회 수: 48 (최근 30일)
Zenia Askar
Zenia Askar 2020년 1월 12일
댓글: Zenia Askar 2020년 1월 14일
Hello! I'm trying to find in an array 'done' the position of a value 'next' without the use of a loop. Then, in this array i want to remove from that position found, the existing element.
out=find(done==next);
done(out)=[];
I tried it this way but is doesnt seem to work. Would you find an arror or recommend another way?

채택된 답변

Robert U
Robert U 2020년 1월 13일
편집: Robert U 2020년 1월 13일
Hi Zenia Askar,
Assuming the content of your variables 'done' and 'next' are numeric your code cannot remove a single value from the matrix without destroying the matrix structure. You should apply logical indexing rather than using 'find()'.
done(done == next) = [];
The result does not represent the matrix structure anymore but is a vector then. To omit that you can place a NaN-value instead.
done(done == next) = NaN;
Kind regards,
Robert
  댓글 수: 1
Zenia Askar
Zenia Askar 2020년 1월 14일
Robert, that was really helpfull thank you

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

추가 답변 (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