我正在编写此代码以从以下矩阵 mapr 中找到邻接矩阵:
'mad' [] [] []
'sister' [] [] []
'dog' 'inter' 'mad' 'said'
对于上面的矩阵,根据我编写的代码,这是我得到的输出,不是想要的:
0 1 1
1 0 1
1 1 0
以下是我的代码:
for i=1:no_of_rows
for j=1:no_of_cols
for m=i+1:no_of_rows
for k=1:no_of_cols
if(~isempty(mapr(i,j)))
if(strcmp(mapr(i,j),mapr(m,k))==0)
Adjmatr(i,m)=1;
Adjmatr(m,i)=1;
end
end
end
end
end
end
有人可以帮我吗。在此先感谢。