how to compare the elements of 2 cell arrays and get their rows from cell2?
Show older comments
Hi Friends, I have 2 cell arrays cell1(1*1) and cell2(1*2) I want to compare the elements of cell1 with cell2 and when all the elements of cell 1 exist in both members of cell2 then get its corresponding row from cell2.
Input:
cell1={gene1;gene2;gene3;gene4;gene5}
cell2={gene1,gene3;gene10,gene100;gene2,gene5}
output
out={gene1,gene3;gene2,gene5}
I have tried isequal and find(ismember) and get empty array.
5 Comments
chocho
on 15 May 2017
chocho
on 15 May 2017
@chocho: your cell arrays are nested inside other cell arrays. Your question does not mention this at all: how do you expect to get answers that actually work?
Anyway, you now have enough MATLAB experience to know how to use cell array indexing. The rest of your question can be solved using intersect.
chocho
on 15 May 2017
chocho
on 15 May 2017
Answers (1)
KSSV
on 15 May 2017
cell1={'gene1';'gene2';'gene3';'gene4';'gene5'} ;
cell2={'gene1','gene3';'gene10','gene100';'gene2','gene5'} ;
out={'gene1','gene3';'gene2','gene5'} ;
[ia,ib] = ismember(cell2,cell1) ;
cell2(ia)
Categories
Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!