How to compare the rows of small file with rows of large cell?

조회 수: 1 (최근 30일)
chocho
chocho 2018년 10월 31일
댓글: chocho 2018년 11월 7일
Hello guys, I want to compare the rows of 2 cells [cell1(627*1) and cell2 (126300*6)], and if they are equal get the columns of that overlapped row from cell2. Inputs:
Expected outputs:
Could anyone plz help me in this issue as i tried with is equal command but no results??
I appreciate any help!
  댓글 수: 2
chocho
chocho 2018년 10월 31일
편집: chocho 2018년 10월 31일
PLz, any one can help me ?
chocho
chocho 2018년 10월 31일
Plz, Can anyone else help me out???

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

채택된 답변

KSSV
KSSV 2018년 10월 31일
Check the below demo code.
% Generate random cells
cell1 = cell(10,1) ;
cell2 = cell(100,2) ;
for i = 1:size(cell1,1)
cell1{1} = rand(3,1) ;
end
for i = 1:size(cell2,1)
for j = 1:size(cell2,2)
cell2{i,j} = rand(10,1) ;
end
end
% GEt common
iwant = cell(size(cell2)) ;
for i = 1:size(cell2,1)
for j = 1:size(cell2,2)
for k = 1:size(cell1,1)
c = ismember(cell1{k},cell2{i,j}) ;
end
end
end
  댓글 수: 21
KSSV
KSSV 2018년 10월 31일
iwant = [C(idx) c2(idx,2:end)] ;
chocho
chocho 2018년 10월 31일
@KSSV Thanks a lot!

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

추가 답변 (1개)

Guillaume
Guillaume 2018년 10월 31일
I am certain we've answered similar questions from you in the past. By now, you should also know that pictures are useless for us and that actually attaching an example of your data is a lot more useful.
With cell arrays, you can use intersect to find which elements overlap between your two columns arrays. It's then trivia to construct your output from the 2nd and 3rd output argument of intersect.
Even easier, would be to convert your cell arrays to tables. The whole operation is then simply a call to innerjoin:
innerjoin(cell2table(UD1), cell2table(whateverthatothercellarrayisnamed), 'Keys', 1)
  댓글 수: 3
Guillaume
Guillaume 2018년 10월 31일
In case you haven't noticed, I also gave you a very simple way to achieve what you want. Just one line of code needed:
innerjoin(cell2table(UD1), cell2table(whateverthatothercellarrayisnamed), 'Keys', 1)
chocho
chocho 2018년 11월 7일
@Guillaume Thanks, This is also a good solution

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

카테고리

Help CenterFile Exchange에서 Schedule Model Components에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by