フィルターのクリア

I would like to get an cell array output by matching 2 cell arrays and returning with corresponding matched values from other cell array.

1 回表示 (過去 30 日間)
I have 2 cell arrays A(6*1) and B(35*2).
A= {'MEG0522';'MEG0523';'MEG0512';'MEG0513';'MEG0312';'MEG0313'};
B= {'MEG0522','LF';'MEG0523','LF';'MEG0512','LF';'MEG0513','LF';'MEG0312','LF';'MEG0313','LF';'MEG0342','LF';'MEG0343','LF';'MEG0122','LF';'MEG0123','LF';'MEG0822','LF';'MEG0823','LF';'MEG0533','LF';'MEG0532','LF';'MEG0543','LF';'MEG0542','LF'{'MEG0923','RF';'MEG1212','RF';'MEG1213','RF';'MEG1223','RF';'MEG1222','RF';'MEG1412','RF';'MEG1413','RF';'MEG0943','RF';'MEG0942','RF';'MEG0933','RF';'MEG0932','RF';'MEG1232','RF';'MEG1233','RF'};
I would like to get an output by matching A with B, returning a cell array say C(6*2) with A values in the column 1 and corresponding B values in column 2.
C = {'MEG0522','LF';'MEG0523','LF';'MEG0512','LF';'MEG0513','LF';'MEG0312','LF'};
Values will not be in an orderly fashion. I would appreciate any support from community members.

採用された回答

Carlos Felipe Rengifo
Carlos Felipe Rengifo 2018 年 7 月 14 日
Please, let me know if the following sentence solves your problem:
B(ismember(B(:,1),A),:)
  4 件のコメント
velmurugan
velmurugan 2018 年 7 月 16 日
Yes. This code creates required cell array.
velmurugan
velmurugan 2018 年 7 月 16 日
Thank you so much for your help and time.

サインインしてコメントする。

その他の回答 (1 件)

Dave
Dave 2018 年 7 月 14 日
編集済み: Dave 2018 年 7 月 14 日
Just because I'm miserable with loops would using intersect meet your needs? Something like
[c,s,t] = intersect(A,B);
C = B(s,:)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by