필터 지우기
필터 지우기

Removing non unique elements from an array after n entries

조회 수: 3 (최근 30일)
Sean
Sean 2014년 6월 30일
댓글: Image Analyst 2014년 6월 30일
If I have an array:
[1 2 3 4 5 6 8 1 2 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 .... 5]
^
How can I remove the remaining 5s after say, here?
  댓글 수: 2
Sean
Sean 2014년 6월 30일
I want to be able to delete after ten 5s (or after some number of 5s in the array) the remaining values in the array without prior knowledge of the location (^).
Cedric
Cedric 2014년 6월 30일
Should the first 5 (between 4 and 6) be accounted in the count of 5s?

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

채택된 답변

Image Analyst
Image Analyst 2014년 6월 30일
out = yourVector(1:18);
  댓글 수: 1
Image Analyst
Image Analyst 2014년 6월 30일
Regarding your additional comment:
m = [1 2 3 4 5 6 8 1 2 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5]
maxNumber = 7; % How many 5's do you want to keep.
indexes = find(m == 5)
m_out = m(1 : indexes(maxNumber))

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by