How to match different cell arrays of different sizes with one cell array of another different size?
2 views (last 30 days)
Show older comments
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 Comment
Guillaume
on 20 Dec 2017
Edited: Guillaume
on 20 Dec 2017
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.
Accepted Answer
Birdman
on 20 Dec 2017
Consider your 1236x2 cell array is named a. Use ismember.
ismember(a,line38)
ismember(a,line60)
and so on.
7 Comments
Birdman
on 20 Dec 2017
Edited: Birdman
on 20 Dec 2017
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).
More Answers (0)
See Also
Categories
Find more on Operators and Elementary Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!