how to get common elements within a cell array?

16 views (last 30 days)
hey all
If i have following array:
how can I compare each cell in this array with all other cells'values. for example for first cell [1,7] i have to compare it with all other cells and find common values. to compare with [2,6,1] we will get 1, to compare with [7,1,3] we will get [1,7] and with [3,5] we will get an empty cell. Similarly after this we will compare 2nd cell [2,6,1] with all cells in array.
please help
Tha saliem
Tha saliem on 6 Mar 2018
Yes they have unique elements.. [2,6,1,1,6] is not possible

Sign in to comment.

Accepted Answer

the cyclist
the cyclist on 6 Mar 2018
Do you need the comparison result? If not, I think this skips right to the final result
aL = 1:length(a);
for na = aL
finalResult{na} = intersect([a{na}],[a{setdiff(aL,na)}]);
This code is a bit obfuscated. But if it gives the result you expect, I can try to help you understand it if you need me to.
Tha saliem
Tha saliem on 6 Mar 2018
Well Thank you so much for this detailed explanation. I have completely understood it. Thanks alot

Sign in to comment.

More Answers (0)


Community Treasure Hunt

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

Start Hunting!