how to find Intersection of strings

I have two strings
c1=B0C0D0E9
c2=B0C0E9
Answer I need is B0C0E9. How to find this??

답변 (1개)

Andrei Bobrov
Andrei Bobrov 2014년 6월 6일
편집: Andrei Bobrov 2014년 6월 6일

0 개 추천

c2 = regexprep(c1,'D0','');
edit
a1 = reshape(c1,2,[])';
a2 = reshape(c2,2,[])';
l = ismember(a1,a2,'rows');
out = reshape(a1(l,:)',1,[]);

댓글 수: 2

Hari
Hari 2014년 6월 6일
What you have answered is static. I just now got the solution.
c4=c1; c3=c2; offst=0; d=length(c3) for i=1:2:d d1=strcat(c3(i),c3(i+1)); d2=strfind(c4,d1); if(d2~=0) offst=offst+1; end end
if(offst==d/2) disp('Found intersecting elements'); end
Andrei Bobrov
Andrei Bobrov 2014년 6월 6일
see code after word edit in my answer

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Vehicle Dynamics Blockset에 대해 자세히 알아보기

태그

질문:

2014년 6월 6일

댓글:

2014년 6월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by