Find

조회 수: 1 (최근 30일)
Alexandros
Alexandros 2011년 12월 19일
Dear Matlabians
I have one string '14022010_003' and = another
13022010_001
14022010_003
15022010_005
i want to find 14022010_003 in the other string. I try to use find findstr or strfind and it says to me that I need to have same matrix dimensions.
The result i am searching is for the script to give me the number 2 (that this string is in position 2) .Any ideas
Thank you

답변 (5개)

karan
karan 2011년 12월 19일
a = {'13022010_001';'14022010_003';'15022010_005'};
find(strcmp(a,'14022010_003'))
should give you the index where the string is matched...

Nirmal Gunaseelan
Nirmal Gunaseelan 2011년 12월 19일
Try making the input strings as part of a cell array. Then use STRFIND or STRCMP which will return a logical array of comparisons.
a = {'13022010_001';'14022010_003';'15022010_005'};
strcmp(a,'14022010_003')
ans =
0
1
0

Walter Roberson
Walter Roberson 2011년 12월 19일
[tf, idx] = ismember('14022010_003', cellstr(['13022010_001'; '14022010_003'; '15022010_005']) );

Daniel Shub
Daniel Shub 2011년 12월 19일
x = '14022010_003'
y = {'13022010_001'
'14022010_003'
'15022010_005'}
find(strcmp(y,x))
Notice the {} and not [] on y.

Alexandros
Alexandros 2011년 12월 20일
I have put strmatch and it works perfectly
  댓글 수: 1
Jan
Jan 2011년 12월 20일
STRMATCH is very inefficient and will be removed in the near future. STRCMP and STRCNCMP are much faster.

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

카테고리

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