Find equal value in two cell arrays

조회 수: 48 (최근 30일)
NA
NA 2020년 10월 19일
댓글: madhan ravi 2020년 10월 20일
I have 2 cells
A = {5;5;[];[];[];[];[];[]};
B = {5;13;4;12;12;12;17;14};
As you see, index one of cell A equals to cell B.
I want to find this index. The below code is not correct for this example.
ismember(cell2mat(A),cell2mat(B),'rows');
  댓글 수: 1
Walter Roberson
Walter Roberson 2020년 10월 19일
Do I understand correctly that for each element of A, you want a list of the indices in B for which any row of the A element matches any row of the B element?
I thought at first you were asking about whether corresponding positions matched, but your A has 9 entries where your B has 8 entries, so you must be wanting to compare every A to every B... by rows??
Could you confirm that in some cases you really will have rows in A or B? And will the entries always be empty or have the same number of columns?

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

채택된 답변

madhan ravi
madhan ravi 2020년 10월 19일
Wanted = find(cellfun(@isequal, A, B))
  댓글 수: 2
Walter Roberson
Walter Roberson 2020년 10월 19일
This does not account for the 'rows' shown in the posting, and does not account for A and B being different lengths.
madhan ravi
madhan ravi 2020년 10월 20일
True sir Walter, assumption was it had equal elements with each as vectors.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by