![]() |
查找MATLAB矩阵中重复次数最多的行
我正在寻找一个函数来查找MATLAB中矩阵中最重复的(即模态)行。就像是:
>> A = [0, 1; 2, 3; 0, 1; 3, 4] A = 0 1 2 3 0 1 3 4 然后运行: >> mode(A, 'rows') 会返回[0, 1] ,最好是第二个输出给出该行发生位置的索引(即[1, 3]' 。 有人知道这样的功能吗? [B]回答:[/B] 您可以使用[URL="http://www.mathworks.com/help/techdoc/ref/unique.html"]UNIQUE[/URL]来获取唯一的行索引,然后对它们调用[URL="http://www.mathworks.com/help/techdoc/ref/mode.html"]MODE[/URL] 。 [uA,~,uIdx] = unique(A,'rows'); modeIdx = mode(uIdx); modeRow = uA(modeIdx,:) %# the first output argument whereIdx = find(uIdx==modeIdx) %# the second output argument [url=https://stackoverflow.com/questions/4783564]更多&回答...[/url] |
所有时间均为北京时间。现在的时间是 23:22。 |
Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.