Finding min values of third column for rows with similar values

1 回表示 (過去 30 日間)
ahmad Mohammadi
ahmad Mohammadi 2020 年 8 月 10 日
編集済み: ahmad Mohammadi 2020 年 8 月 11 日
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 件のコメント
ahmad Mohammadi
ahmad Mohammadi 2020 年 8 月 11 日
編集済み: ahmad Mohammadi 2020 年 8 月 11 日
Thats great. I spent like 5 hours to reach a very bad coding. But, you saved me
Thanks,

サインインしてコメントする。

その他の回答 (1 件)

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

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by