Filter löschen
Filter löschen

FInd vector in matrix

66 Ansichten (letzte 30 Tage)
Kris zenitis
Kris zenitis am 14 Mai 2011
Kommentiert: Esubalew am 25 Jul. 2017
Lets assume that I have a matrix A 300x2 with x y coordinates. I want to find how many times a specific [x y] exists in this matrix A. I ve tried this but find can search only single values.
i = find(A == [x y]);
Any idea?????
  1 Kommentar
Azzi Abdelmalek
Azzi Abdelmalek am 19 Feb. 2014
[Kris zenitis commented]
Yeah thank you man!!

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Jan
Jan am 14 Mai 2011
Another method:
I = sum(A(:, 1) == x & A(:, 2) == y);
EDITED: Buggy multiplication method removed. Thanks Andrei!
This method is about 50 times faster than ISMEMBER(A, b, 'rows').
  3 Kommentare
Jan
Jan am 14 Mai 2011
@Andrei: You are right. But the multiplication is slower than the AND operator. Therefore I've removed this method.
Esubalew
Esubalew am 25 Jul. 2017
Hi Jan,
The method you suggested above is a good one, but incase if A is 1000 by 100 matrix or a bigger matrix, it there a better way to cind the row of A, A_i such that A_i ==v for some vector v of size =size(A,2)?
Thank you!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Matt Fig
Matt Fig am 14 Mai 2011
For example:
A = reshape(1:12,6,2) % A sample matrix for demonstration...
I = ismember(A,[4 10],'rows');
If you want to find how many there are, use:
S = sum(I)

Kategorien

Mehr zu Language Fundamentals 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