Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab 为其他列中的每个唯一2个值查找列中的最低值_Matlab_Matrix_Combinations_Unique Values - Fatal编程技术网

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];