我有text.txt,其中包含单词和数字。
d = reshape(textread('text.txt','%s','delimiter','\t'),2,2)'
if h(1,1)=='apple'
k=1
end
这不起作用。
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
它是用非Matlab方式编写的,但你知道我想做什么。
如果text和text2是数字矩阵,这种类型的工作可能很容易。但它们是弦乐。
我如何执行与数字矩阵相同的操作?
答案 0 :(得分:1)
我认为您正在寻找字符串操作实用程序。以下是一些:
% 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
:)