How can I compare two cell arrays inside two different structures?

3 ビュー (過去 30 日間)
Bhushan Dhamale
Bhushan Dhamale 2018 年 5 月 18 日
コメント済み: Ameer Hamza 2018 年 5 月 22 日
I have two structures model and dataMtb. I want to compare the fields model.grRules and dataMtb.gene having dimensions 1128*1 and 4109*1 respectively. I want to create a cell array which would give me a list of only those genes which are common between the two cell arrays. I am attaching the .mat files for reference. Please note that the cells in model.grRules cell array may contain names of more than one gene in each cell. How do I achieve the above objective?

採用された回答

Ameer Hamza
Ameer Hamza 2018 年 5 月 18 日
編集済み: Ameer Hamza 2018 年 5 月 18 日
This code will extract common values of genes which occur in either of the vectors.
list1 = string(dataMtb.gene);
list2 = string(iEK1011.grRules);
commonValues = list1(cellfun(@(x) any(contains(list2, x)), list1));
  2 件のコメント
Bhushan Dhamale
Bhushan Dhamale 2018 年 5 月 22 日
Thank you for the lucid code Ameer.
Ameer Hamza
Ameer Hamza 2018 年 5 月 22 日
You are welcome.

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

その他の回答 (0 件)

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by