Problem with "Intersect" function
Show older comments
Hellow everyone! I have 2 cells.
A = '1,2,3';
B= '1,4,5,6';
But, When i try to use intersect function to get the common element(s) as my result, say
C = intersect(A, B);
I am getting an empty cell like this.
C =
Empty cell array: 1-by-0
Kindly help me, My result shall show like
C='1'
Your help will be highly appreciated!
4 Comments
alice
on 22 Jun 2017
Hi,
I think your A and B are:
A = {'1,2,3'};
B = {'1,4,5,6'};
This means A is a cell containing the string '1,2,3' and B is a cell containing the string '1,4,5,6'. These strings are different, so the intersection of A and B is empty.
To get what you want, the numbers should be separated (different strings, or just numbers).
How are A and B defined in your code?
Stephen23
on 22 Jun 2017
"Problem with "Intersect" function"
There is no problem with intersect: you have given it two cell arrays containing different strings, so clearly the intersection is an empty cell array. This is exactly as the documentation states.
pradeep kumar
on 22 Jun 2017
pradeep kumar
on 22 Jun 2017
Accepted Answer
More Answers (1)
KSSV
on 22 Jun 2017
A = [1,2,3] ;
B = [1,4,5,6];
intersect(A,B)
OR
A = '1,2,3';
B= '1,4,5,6';
intersect(str2num(A),str2num(B))
1 Comment
pradeep kumar
on 22 Jun 2017
Categories
Find more on Data Type Identification in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!