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))
1 件のコメント
pradeep kumar
2017 年 6 月 22 日
カテゴリ
ヘルプ センター および File Exchange で Data Type Identification についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!