MATLAB Answers

0

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

Asked by Bhushan Dhamale on 18 May 2018
Latest activity Commented on by Ameer Hamza
on 22 May 2018

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?

  0 Comments

Sign in to comment.

Products

1 Answer

Answer by Ameer Hamza
on 18 May 2018
Edited by Ameer Hamza
on 18 May 2018
 Accepted Answer

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));