problem while using 'intersect' between strings
5 次查看(过去 30 天)
显示 更早的评论
Hi:
I have two strings:
s1='bound10-wall1.out'
s2='bound10-wall24.out'
and I need the intersect between them, then, I use the result posted here: https://www.mathworks.com/matlabcentral/answers/125711-how-can-i-find-the-common-elements-of-2-cell-arrays-of-strings
[C,ia,ib] = intersect(s1,s2, 'stable');
the result is:
C='bound10-wal.t'
however, I think the expected result should be:
'bound10-wall.out'
so I would like to know if there is any mistake with my understanding?
Thanks!
Yu
0 个评论
采纳的回答
Star Strider
2019-10-8
The letter ‘l’ appears twice in both strings, so is only returned once in the intersect result.
Yopu will get a similar result with:
s1u = unique(s1, 'stable')
s2u = unique(s2, 'stable')
and for the same reason.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!