Finding min values of third column for rows with similar values

1 次查看(过去 30 天)
Hi,
I have a Table
2.0000 0 3.1971
1.0000 0 3.1971
3.0000 0 6.4662
1.0000 0 6.4662
3.0000 0 9.6356
2.0000 0 9.6356
2.0000 1 7
1.0000 1 5
3.0000 1 6
1.0000 1 10
3.0000 1 44
2.0000 1 12
Now, what I want is that find minimum value of third column for the first column with equal value in each loop of second column.
Maybe it is better to see the result what I mean.
2.0000 0 3.1971
1.0000 0 3.1971
3.0000 0 6.4662
2.0000 1 7
1.0000 1 5
3.0000 1 6
Really appreciate
  1 个评论
Stephen23
Stephen23 2020-8-11
编辑:Stephen23 2020-8-11
The example is not clear for me. You wrote that you want the "...minimum value of third column...", can you please explain why your example output contains this row:
...
2.0000 1 7
...
when the input matrix contains both of these rows
...
2.00000 1.00000 7.00000
...
2.00000 1.00000 2.00000
As far as I can tell, 2 is less than 7, so why does the expected output not contain the "minimum value" ?

请先登录,再进行评论。

采纳的回答

Stephen23
Stephen23 2020-8-11
编辑:Stephen23 2020-8-11
>> M = [2.0000,0,3.1971;1.0000,0,3.1971;3.0000,0,6.4662;1.0000,0,6.4662;3.0000,0,9.6356;2.0000,0,9.6356;2.0000,1,7;1.0000,1,5;3.0000,1,6;1.0000,1,10;3.0000,1,44;2.0000,1,2]
M =
2.0000 0 3.1971
1.0000 0 3.1971
3.0000 0 6.4662
1.0000 0 6.4662
3.0000 0 9.6356
2.0000 0 9.6356
2.0000 1.0000 7.0000
1.0000 1.0000 5.0000
3.0000 1.0000 6.0000
1.0000 1.0000 10.0000
3.0000 1.0000 44.0000
2.0000 1.0000 2.0000
>> [U,X,Y] = unique(M(:,1:2),'stable','rows');
>> V = accumarray(Y,M(:,3),size(X),@min);
>> A = [U,V]
A =
2.0000 0 3.1971
1.0000 0 3.1971
3.0000 0 6.4662
2.0000 1.0000 2.0000
1.0000 1.0000 5.0000
3.0000 1.0000 6.0000

更多回答(1 个)

Sudheer Bhimireddy
Sudheer Bhimireddy 2020-8-11
If the order is not important, look at sort function.

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by