필터 지우기
필터 지우기

FInd vector in matrix

조회 수: 66 (최근 30일)
Kris zenitis
Kris zenitis 2011년 5월 14일
댓글: Esubalew 2017년 7월 25일
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
Azzi Abdelmalek
Azzi Abdelmalek 2014년 2월 19일
[Kris zenitis commented]
Yeah thank you man!!

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

채택된 답변

Jan
Jan 2011년 5월 14일
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
Jan
Jan 2011년 5월 14일
@Andrei: You are right. But the multiplication is slower than the AND operator. Therefore I've removed this method.
Esubalew
Esubalew 2017년 7월 25일
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!

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

추가 답변 (1개)

Matt Fig
Matt Fig 2011년 5월 14일
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)

카테고리

Help CenterFile Exchange에서 Language Fundamentals에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by