Finding an array of numbers in an array

Hi
I have the attached coords_17 array, which is 2092 x 3 dimensional. Within this array, I want to find say the row which contains the coordinates [44, -30, 54]. However, the following commands fails somehow:
find(coords_17 == [44, -30, 54])
How can I find the relevant coordinates correctly? Many thanks

 Akzeptierte Antwort

Star Strider
Star Strider am 30 Sep. 2018

1 Stimme

I would use the ismember (link) function.

Try this:

target = [44, -30, 54];
Lidx = ismember(coords_17, target, 'rows');
row_number = find(Lidx)
row_number =
     2

4 Kommentare

MiauMiau
MiauMiau am 30 Sep. 2018
Thanks! What is the reason it does not work with a simple "find"?
Star Strider
Star Strider am 30 Sep. 2018
Correct.
Using ismember (or ismembertol if you are matching non-integers) first, and then using find is much more efficient.
It might be possible with find, however that would likely require matching each column and then searching for matching row indices.
MiauMiau
MiauMiau am 30 Sep. 2018
thx
Star Strider
Star Strider am 30 Sep. 2018
As always, my pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Operators and Elementary Operations finden Sie in Hilfe-Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by