Filter löschen
Filter löschen

Removing non unique elements from an array after n entries

1 Ansicht (letzte 30 Tage)
Sean
Sean am 30 Jun. 2014
Kommentiert: Image Analyst am 30 Jun. 2014
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 Kommentare
Sean
Sean am 30 Jun. 2014
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 am 30 Jun. 2014
Should the first 5 (between 4 and 6) be accounted in the count of 5s?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Image Analyst
Image Analyst am 30 Jun. 2014
out = yourVector(1:18);
  1 Kommentar
Image Analyst
Image Analyst am 30 Jun. 2014
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))

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by