Matlab 为其他列中的每个唯一2个值查找列中的最低值
我有一个矩阵,一个小样本的数据:Matlab 为其他列中的每个唯一2个值查找列中的最低值,matlab,matrix,combinations,unique-values,Matlab,Matrix,Combinations,Unique Values,我有一个矩阵,一个小样本的数据: A= 1 3 658 2 3 475 5 3 769 1 3 856 6 7 1579 2 3 678 5 3 118 6 7 617 现在,我想为A列和B列的每个唯一组合找到C列中的最小值,最好是在一个新矩阵中 因此,输出将是: B= 1 3 658 2 3 475 5 3 118 6 7 617 你能告诉我做这件事的最佳方法吗? 提前感谢将和与行选项结合使用,应该可以获得所需的结果 A = sortrows(A); % After
A=
1 3 658
2 3 475
5 3 769
1 3 856
6 7 1579
2 3 678
5 3 118
6 7 617
现在,我想为A列和B列的每个唯一组合找到C列中的最小值,最好是在一个新矩阵中
因此,输出将是:
B=
1 3 658
2 3 475
5 3 118
6 7 617
你能告诉我做这件事的最佳方法吗?
提前感谢将和与行
选项结合使用,应该可以获得所需的结果
A = sortrows(A); % After the sort unique combinations will be adjacent and with increasing values in 3rd column
[~,ia] = unique(A(:,1:2),'rows'); % Find index of all the unique comb in col 1 & 2, unique only returns the first index
B = A(ia,:);
and与行
选项的组合应该会提供所需的结果
A = sortrows(A); % After the sort unique combinations will be adjacent and with increasing values in 3rd column
[~,ia] = unique(A(:,1:2),'rows'); % Find index of all the unique comb in col 1 & 2, unique only returns the first index
B = A(ia,:);
如果前两列中的值为正整数,而第三列中的值为非零,也可以按如下方式执行:
[ii, jj, vv] = find(accumarray(A(:,[1 2]), A(:,3), [], @min, 0, true));
B = [ii jj vv];
如果前两列中的值为正整数,而第三列中的值为非零,也可以按如下方式执行:
[ii, jj, vv] = find(accumarray(A(:,[1 2]), A(:,3), [], @min, 0, true));
B = [ii jj vv];