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 Center および File ExchangeOperators and Elementary Operations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by