필터 지우기
필터 지우기

how to find cell array intersection

조회 수: 8 (최근 30일)
Shivik Garg
Shivik Garg 2017년 9월 12일
답변: Walter Roberson 2017년 9월 12일
i have cell array
y [1x4] [1x5] [1x6]
if have to find out common elements among
y{1}&y{2} y{1}& y{3} y{2}&y{3]
how can I use the intersect function to do it
  댓글 수: 1
James Tursa
James Tursa 2017년 9월 12일
Please provide a small example showing the input and desired output, giving a clear description of the complete rules involved for getting the output.

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

답변 (1개)

Walter Roberson
Walter Roberson 2017년 9월 12일
[I, J] = ndgrid(1:length(y));
result = arrayfun(@(tI,tJ) intersect(y{tI}, y{tJ}), I, J 'uniform', 0);
The result will be a symmetric cell array. Each pair would have been evaluated twice. Depending on the size of the array, avoiding the double evaluation could end up slower.
leny = length(y);
result = cell(leny-1, leny-1);
for J = 1 : leny - 1
for K = J+1 : leny
result{J,K-1} = intersect(y{J}, y{K});
end
end
This will give a cell array of results with the diagonal deleted and the entries below the diagonal left empty.

카테고리

Help CenterFile Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by