如何消除在MATLAB单元阵列重复整数 [英] how to eliminate repeating integers from cell array in matlab
问题描述
我有[字*句子]矩阵,其中的句子有重新present例句号码从一个文本文件,从这个矩阵我构建一维数组的整数[1 * N]这说明文字以及其中的句子,他们发生一些明智的。
一旦上述步骤完成后我已经采取路口检查哪些词一起出现在句子中的code是如下:
i have [words*sentences]matrix where sentences have integers that represent sentence numbers from a text document from this matrix i have constructed 1D array of [1*N] which shows words and in which sentences they occur number wise. once above step is done i have taken intersection to check which words occur together in which sentences the code is as follows:
OccursTogether = cell(length(Out1));
for ii=1:length(Out1)
for jj=ii+1:length(Out1)
OccursTogether{ii,jj} = intersect(Out1{ii},Out1{jj});
end
end
celldisp(OccursTogether)
样本输出如下表示句子中出现第一个字
与第2个字出现在句{11 12 13}和字1 {5 10 16}同一个词时用字3句子{9} 14等,直到第N个字:
the sample output is as follows which shows 1st word occurs in sentence {5 10 16} same word occurs with 2nd word in sentence {11 12 13} and word 1 occurs with word 3 in sentence {9 14} and so on till the Nth word:
OccursTogether{1,1} = 5 10 16
OccursTogether{2,1} = 5 12 16
OccursTogether{3,1} = 9 14
现在我想要的是在展示基于OccursTogether单元阵列一行输出,无需重复一句话数字如下:
now what i want is to show output in one line based upon OccursTogether cell array without repeating sentence numbers as below:
output: {5 9 10 12 14 16}
任何帮助将我AP preciated ..
any help would me appreciated..
推荐答案
如果我理解正确的:
result = unique([OccursTogether{:}]);
在你的榜样,这给
result =
5 9 10 12 14 16
这篇关于如何消除在MATLAB单元阵列重复整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!