【发布时间】:2026-02-16 18:35:01
【问题描述】:
我有一组字符串(作为 Nx1 矩阵)和一个字典(Mx1),其中包含字符串中的所有单词。 例如:
strings= ['i went to the mall'; 'i am hungry']
dictionary = ['i','went','to','the', 'mall','am','hungry']
如果相应的推文中存在相应的单词,我想创建一个矩阵(大小为 MxN),其中单元格包含 1。我怎么能在matlab中做到这一点?
我试过这样做:
for i=1:len_of_dict
for j=1:len_of_str
temp=strfind(string1(j),dict(i));
x=find(cellfun(@isempty,temp));
xx = isempty(x);
if(xx~=0)
vec(i,j)=1;
end
end
end
但是我得到的向量不正确。请帮忙!
【问题讨论】:
标签: matlab dictionary matrix