Finding min values of third column for rows with similar values

1 vue (au cours des 30 derniers jours)
ahmad Mohammadi
ahmad Mohammadi le 10 Août 2020
Modifié(e) : ahmad Mohammadi le 11 Août 2020
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 commentaire
Stephen23
Stephen23 le 11 Août 2020
Modifié(e) : Stephen23 le 11 Août 2020
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" ?

Connectez-vous pour commenter.

Réponse acceptée

Stephen23
Stephen23 le 11 Août 2020
Modifié(e) : Stephen23 le 11 Août 2020
>> 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 commentaire
ahmad Mohammadi
ahmad Mohammadi le 11 Août 2020
Modifié(e) : ahmad Mohammadi le 11 Août 2020
Thats great. I spent like 5 hours to reach a very bad coding. But, you saved me
Thanks,

Connectez-vous pour commenter.

Plus de réponses (1)

Sudheer Bhimireddy
Sudheer Bhimireddy le 11 Août 2020
If the order is not important, look at sort function.

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by