필터 지우기
필터 지우기

please help me sort this out

조회 수: 1 (최근 30일)
Elysi Cochin
Elysi Cochin 2014년 2월 6일
댓글: Elysi Cochin 2014년 2월 7일
please can someone help me with a very simple coding... i know its simple but i'm not getting...
i 2 matrix with dimensions below,
A = with 13 rows and 125 columns
B = with 1 row and 125 column,
i want to find which row of A matches with B if it does not match, i want to get the row which matches with most columns of B
please someone help me to sort it out, eg if A is,
34 44 55 66
23 33 22 27
21 44 66 34
if B = 23 33 22 27 i want ans = 2
if B = 27 44 66 34 i want ans = 3

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2014년 2월 6일
A=[4 44 55 66
23 33 22 27
21 44 66 34]
B=[23 33 22 27]
[~,ii]=max(sum(ismember(A,B),2))
  댓글 수: 2
Elysi Cochin
Elysi Cochin 2014년 2월 6일
so simple... thank you so much sir.... i was using for loop and if condition.... great!!! you just did that in one line..... thank you so much sir....
Jos (10584)
Jos (10584) 2014년 2월 6일
+1 Azzi
However, note that this does not care about the column order, which may or may not matter.
% Which row of A matches B the most?
A = [1 2 3 5 ;
4 3 2 1]
B = [1 2 3 4]

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

추가 답변 (1개)

Jos (10584)
Jos (10584) 2014년 2월 6일
When column number does matter:
% A : a N-by-M array
% B : a 1-by-N row vector
[~, ii] = max(sum(bsxfun(@eq,A,B),2))
RESULT = A(ii,:)
  댓글 수: 1
Elysi Cochin
Elysi Cochin 2014년 2월 7일
thank you so much for explaining me the difference....

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

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by