Delete element from a vector within a given range

조회 수: 2 (최근 30일)
shalipse
shalipse 2018년 4월 6일
댓글: shalipse 2018년 4월 6일
Hi everyone,
Assuming I have a Vector say A = [2 3 1 8 1 8 4 1 3 6 7 5 6 8 1], and I want to delete the first 7 elements that are less than two. Therefore having A = [2 3 8 8 4 1 3 6 7 5 6 8 1]. Can someone please explain to me how to do this in Matlab?
Thanks
  댓글 수: 1
David Fletcher
David Fletcher 2018년 4월 6일
Since your example matrix doesn't actually have seven elements less than two, I am wondering whether you actually mean the first 7 elements less than 2, or the elements less than 2 with an index less than seven?

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

채택된 답변

Walter Roberson
Walter Roberson 2018년 4월 6일
"I want to delete the first 7 elements that are less than two"
A( find(A < 2, 7, 'first') ) = [];
You only have four elements that are less than 2, so it will delete all four of them.
I think you used the wrong wording and that what you want is
A( A(1:7) < 2 ) = [];
  댓글 수: 1
shalipse
shalipse 2018년 4월 6일
Hello,
Thanks for the quick response and solution. I just realised that I didn't ask my question accurately.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by