find index of an arry in matlab

2 Ansichten (letzte 30 Tage)
Rica
Rica am 12 Aug. 2019
Kommentiert: Rica am 12 Aug. 2019
I have a big array and i want to find the index of the element of an array in the big array.
I know this could be easily solves with functions such find or ismember. But my goal is to give the index of the first number in the case when the the number is present more than one time in the big array like the numbers 2.2, 5.1, 6 and 7.
e.g
BigArray=[1 2 2.2 3 2.2 5 5.1 5.1 6 6 7 7.........]
ArryToBeFound=[1 2 2.2 5.1 6 7]
Solution:
index=[1 2 3 7 9 11]
Do you have any idea how to solve this?
Thank you

Akzeptierte Antwort

Guillaume
Guillaume am 12 Aug. 2019
ismember is indeed the functio to use:
[~, where] = ismember(ArrayToBeFound, BigArray)
where is the index of the 1st element where the element is found, or 0, if not found. ismember guarantees that it's always the first index.
  1 Kommentar
Rica
Rica am 12 Aug. 2019
next time i should read the documentation of ismember ;-)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Structures 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