필터 지우기
필터 지우기

Compare cells in cell array to find common columns

조회 수: 1 (최근 30일)
sr9497
sr9497 2022년 3월 30일
편집: sr9497 2022년 4월 4일
I have two cell arrays, data 1 (1x6 cell) and data 2 (1x8 cell) where each cell consists of 3x5 double or 3x4 double. I would like to compare these cell arrays and find out which cells have at least two columns in common, e.g. data1{1,1} and data2{1,1} have two columns in common. Then I would like to store all these cells in a new cell array.
What is the best way to do this?

채택된 답변

Matt J
Matt J 2022년 3월 30일
편집: Matt J 2022년 3월 30일
You should just use an explicit loop over all combinations of cells. With cell arrays, there is never a good reason to look for some kind of fancy vectorization, and certainly not with arrays as small as what you've posted.
  댓글 수: 2
sr9497
sr9497 2022년 3월 30일
Thank you for your answer. Which function would you suggest I use to be able to find the common columns if the cell arrays and the cells have different sizes?
Matt J
Matt J 2022년 3월 30일
편집: Matt J 2022년 3월 30일
You can transpose the matrices and use intersect(__,'rows') if the agreement between columns is to be exact, otherwise ismembertol(__,'ByRows', true)

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by