String MatLab使用";至于;及;如果;对于字符串
我有text.txt,其中包含单词和数字 1.我想用“for”和“if”来表示包含字符串的单元格或矩阵。String MatLab使用";至于;及;如果;对于字符串,string,matlab,text,textscan,String,Matlab,Text,Textscan,我有text.txt,其中包含单词和数字 1.我想用“for”和“if”来表示包含字符串的单元格或矩阵。 这不管用 2.我想做这样的事。 这是写在非Matlab的方式,但你知道我想做什么 如果text和text2是数字矩阵,那么这类工作可能很容易。但它们是弦 我如何才能对数值矩阵执行相同的操作?我想您正在寻找字符串操作实用程序。以下是一些: % Case-sensitive comparison strcmp('apple', 'apple') == true strcmp('apple',
这不管用 2.我想做这样的事。
这是写在非Matlab的方式,但你知道我想做什么 如果text和text2是数字矩阵,那么这类工作可能很容易。但它们是弦
我如何才能对数值矩阵执行相同的操作?我想您正在寻找字符串操作实用程序。以下是一些:
% Case-sensitive comparison
strcmp('apple', 'apple') == true
strcmp('apple', 'orange') == false
% Case-INsensitive comparison
strcmpi('apple', 'AppLe') == true
strcmpi('apple', 'orange') == false
% Compare first N characters, case sensitive
strncmp('apple', 'apples are delicious', 5) == true
% Compare first N characters, case INsensitive
strncmpi('apple', 'AppLes are delicious', 5) == true
% find strings in other strings
strfind('I have apples and oranges', 'apple')
ans =
8 % match found at 8th character
% find any kind of pattern in (a) string(s)
regexp(...)
我甚至不打算从
regexp
开始……只要读一下doc regexp
:)字符串是字符数组。例如:S='Hello'
那么S(end)
将是'o'
。使用单元格存储字符串矩阵(请参见)。使用(d{1,1},'apple')
代替d{1,1}=='apple'
。
for m=1:size(text)
for n=1:size(text2)
if text2(n,3) contains 'apple' (such as "My apple his, her")
if last word of text2(n,3) is text(m,2)
output(m,1)==text(m,2)
output(m,2)==text(m,1)
end
end
end
end
% Case-sensitive comparison
strcmp('apple', 'apple') == true
strcmp('apple', 'orange') == false
% Case-INsensitive comparison
strcmpi('apple', 'AppLe') == true
strcmpi('apple', 'orange') == false
% Compare first N characters, case sensitive
strncmp('apple', 'apples are delicious', 5) == true
% Compare first N characters, case INsensitive
strncmpi('apple', 'AppLes are delicious', 5) == true
% find strings in other strings
strfind('I have apples and oranges', 'apple')
ans =
8 % match found at 8th character
% find any kind of pattern in (a) string(s)
regexp(...)