How to match different cell arrays of different sizes with one cell array of another different size?

조회 수: 2 (최근 30일)
I have different cell arrays with different sizes 1×3 and 1×2:
line38 = {'38-1', '38-2', '38-3'};
line60 = {'60-1', '60-2', '60-3'};
line48 = {'48-1', '48-2'};
line52 = {'52-1', '52-2'};
line61 = {'61-1', '61-2', '61-3'};
line76 = {'76-1', '76-2', '76-3'};
line66 = {'66-1', '66-2'};
line70 = {'70-1', '70-2'};
line26 = {'26-1', '26-2', '26-3'};
line94 = {'94-1', '94-2', '94-3'};
line89 = {'89-1', '89-2'};
line90 = {'90-1', '90-2'};
I need to match these cells with a cell array of 1236×2
  댓글 수: 1
Guillaume
Guillaume 2017년 12월 20일
편집: Guillaume 2017년 12월 20일
line38=...
line60=...
line48=...
linexx=...
Do not do that!. If you're numbering variables (or any kind of sequential naming) you're doing it wrong. Clearly, all these variables are related so they all belong together in a container. In your case a cell array (which thus would itself contain cell arrays).
Whatever the solution is to your question it will be much harder to implement with numbered variable.
See faq-how-can-i-create-variables-a1-a2-a10-in-a-loop and many other posts for why numbering variables is an extremely bad practice.

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

채택된 답변

Birdman
Birdman 2017년 12월 20일
Consider your 1236x2 cell array is named a. Use ismember.
ismember(a,line38)
ismember(a,line60)
and so on.
  댓글 수: 7
Birdman
Birdman 2017년 12월 20일
편집: Birdman 2017년 12월 20일
Hi again,
The problem is that you try to search the entire cell array, but you are interested in second column. All you need to do is:
find(ismember(veh_linklanes(:,2),line38))
and you will see the indexes(rows) in second column(if there bigger one contains the small one).

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by