MATLAB如何半段一个字符数组中含有特定字符?
比如我有一个字符数组str,里面有很多字符,我想判断这个数组里是否含有JPG这个字符串,JPG是连在一起的,如果有,则返回1,没有就返回0。请问MATLAB有现成的命令么...
比如我有一个字符数组str,里面有很多字符,我想判断这个数组里是否含有JPG这个字符串,JPG是连在一起的,如果有,则返回1,没有就返回0。请问MATLAB有现成的命令么?如果自己写,应该怎么写?谢谢大家。
展开
3个回答
展开全部
>> help strfind
STRFIND Find one string within another.
K = STRFIND(TEXT,PATTERN) returns the starting indices of any
occurrences of the string PATTERN in the string TEXT.
STRFIND will always return [] if PATTERN is longer than TEXT.
Examples
s = 'How much wood would a woodchuck chuck?';
strfind(s,'a') returns 21
strfind('a',s) returns []
strfind(s,'wood') returns [10 23]
strfind(s,'Wood') returns []
strfind(s,' ') returns [4 9 14 20 22 32]
See also strcmp, strncmp, regexp.
Overloaded methods:
cell/strfind
Reference page in Help browser
doc strfind
如果是针对文件名,这个或许也有帮助
>> help fileparts
FILEPARTS Filename parts.
[PATHSTR,NAME,EXT] = FILEPARTS(FILE) returns the path,
filename and extension for the specified file.
FILEPARTS is platform dependent.
You can reconstruct the file from the parts using
fullfile(pathstr,[name ext versn])
The fourth output, VERSN, of FILEPARTS will be removed in a future
release.
See also fullfile, pathsep, filesep.
Reference page in Help browser
doc fileparts
STRFIND Find one string within another.
K = STRFIND(TEXT,PATTERN) returns the starting indices of any
occurrences of the string PATTERN in the string TEXT.
STRFIND will always return [] if PATTERN is longer than TEXT.
Examples
s = 'How much wood would a woodchuck chuck?';
strfind(s,'a') returns 21
strfind('a',s) returns []
strfind(s,'wood') returns [10 23]
strfind(s,'Wood') returns []
strfind(s,' ') returns [4 9 14 20 22 32]
See also strcmp, strncmp, regexp.
Overloaded methods:
cell/strfind
Reference page in Help browser
doc strfind
如果是针对文件名,这个或许也有帮助
>> help fileparts
FILEPARTS Filename parts.
[PATHSTR,NAME,EXT] = FILEPARTS(FILE) returns the path,
filename and extension for the specified file.
FILEPARTS is platform dependent.
You can reconstruct the file from the parts using
fullfile(pathstr,[name ext versn])
The fourth output, VERSN, of FILEPARTS will be removed in a future
release.
See also fullfile, pathsep, filesep.
Reference page in Help browser
doc fileparts
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
使用strfind函数。
S = 'Find the starting indices of the pattern string';
strfind(S, 'in')
ans =
2 15 19 45使用regexp函数。
str = 'bat cat can car COAT court cut ct CAT-scan';
regexp(str, 'c[aeiou]+t')
ans =
5 28
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询