how do i find matching row from an array?

조회 수: 39 (최근 30일)
ME
ME 2015년 3월 16일
댓글: Star Strider 2025년 4월 21일
I have an array and i want to find matching elements of a variable from the array how do i do that? p = [1 2;3 1]; c = [3 1] if (p == c) doesn't seem to work and i get an error saying matrix dimentions must agree

채택된 답변

Star Strider
Star Strider 2015년 3월 16일
Use the ismember function with the 'rows' option:
p = [1 2;3 1];
c = [3 1];
[q, idx] = ismember(c, p, 'rows');
The ‘idx’ variable contains the row of ‘p’ that matches the data in ‘c’. The ‘q’ variable tells you if there is a match somewhere (1) or not (0).
  댓글 수: 2
Wesley
Wesley 2025년 4월 21일
Thanks for your answer! It helped me in a pinch!
Star Strider
Star Strider 2025년 4월 21일
@Wesley — My pleasure!
A Vote would be appreciated!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by