필터 지우기
필터 지우기

Searching and Manipulating Cell Array

조회 수: 1 (최근 30일)
Sam Da
Sam Da 2012년 10월 19일
I have a cell array A:
[3,2]
[2,4]
[4,5]
[2,5]
[6]
and cell array B:
[2,3,4]
[2,5]
[4,5,6]
In the array B I can see that [2,3,4] is made of union of [3,2] and [2,4] from A. [2,5] in B is made from union of only [2,5] from A. [4,5,6] in B is made of [4,5] and [6] in A.
So, I want to find the index of elements in A union of which make each array element of B. How do I do this?
Thanks guys
  댓글 수: 2
Azzi Abdelmalek
Azzi Abdelmalek 2012년 10월 19일
what are the sizes of elments in B? can they be >3. The same question about A
Sam Da
Sam Da 2012년 10월 19일
Yes they can be of any length. Thanks for interest. I think Matt's code already works for a general case. But if you have a simpler solution please do post.

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

채택된 답변

Matt J
Matt J 2012년 10월 19일
편집: Matt J 2012년 10월 19일
subsetmap=false(length(A), length(B));
for bb=1:length(B)
for aa=1:length(A)
subsetmap(aa,bb) = all(ismember(A{aa},B{bb}));
end
end
%this next line is unnecessary if logical indexing is sufficient
indices=arrayfun(@(col) find(subsetmap(:,col)),1:length(B),'uni',0);
  댓글 수: 3
Matt J
Matt J 2012년 10월 19일
Yes. My code already does that.
Matt J
Matt J 2012년 10월 19일
By the way. My code doesn't check to see whether all B{i} can actually be formed from the union of some A{j}. It only works if this is already the case. I leave it to you to add the appropriate error checks.

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by