フィルターのクリア

find column from list then save cell

2 ビュー (過去 30 日間)
Vincent I
Vincent I 2014 年 6 月 23 日
コメント済み: Vincent I 2014 年 6 月 24 日
Hi,
I have two cells:
A = {'One','Four','Five'};
B = {'One','Two','Three','Four','Five';1 2 3 4 5;6 7 8 9 10};
Find A in B = C
C = {'One','Four','Five';1 4 5;6 9 10}
As shown above, I would like find the columns from A in B and the save them to another cell C without using either a for or while loop.
Cell A can have different numbers so whats shown above its not always the same.
Thank you

採用された回答

Andrei Bobrov
Andrei Bobrov 2014 年 6 月 23 日
C = B(:,ismember(B(1,:),A))

その他の回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 6 月 23 日
A = {'One','Four','Five'};
B = {'One','Two','Three','Four','Five';1 2 3 4 5;6 7 8 9 10};
If you work with tables
BB=cell2table(B(2:end,:),'VariableNames',B(1,:))
C=BB(:,A)
  1 件のコメント
Vincent I
Vincent I 2014 年 6 月 24 日
cell2table did not work for me. I'm sure with some tweaking i could have worked.
Thank you very much for your help

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

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by