Problem with "Intersect" function
이전 댓글 표시
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
alice
2017년 6월 22일
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
2017년 6월 22일
"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
2017년 6월 22일
pradeep kumar
2017년 6월 22일
채택된 답변
추가 답변 (1개)
KSSV
2017년 6월 22일
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))
카테고리
도움말 센터 및 File Exchange에서 Data Type Identification에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!