필터 지우기
필터 지우기

How do I compare similar string?

조회 수: 6 (최근 30일)
MIHYUN
MIHYUN 2014년 7월 29일
편집: Azzi Abdelmalek 2014년 7월 29일
I have two types of string.
  1. Democratic Republic of the Congo
  2. Congo (Dem. Rep.)
I want to save the string in the column of each ('Democratic' 'Republic' 'of' 'the' 'Congo' ...)
And When comparing #1, #2 , And outputs it to #2 ( Congo (Dem. Rep.) ), If there is a match in one string (Congo).
What should I do?
Please help me.

답변 (1개)

Michael Haderlein
Michael Haderlein 2014년 7월 29일
With intersect, you will find the matching one string*:
>> sstr1=strsplit(str1,' ');
>> sstr2=strsplit(str2,' ');
>> intersect(sstr1,sstr2)
ans =
'Congo'
However, I'm not sure if that's really what you want - if you compare "Democratic Republic of the Congo" with "People's Republic of China", you will also get some nonempty result.
*Please note that I have an older Matlab release which does not include the strsplit function. However, I have a self-written one (which follows a little different syntax). In case the string splitting in my code does not work, it's for that reason.

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by