Finding min values of third column for rows with similar values

1 visualización (últimos 30 días)
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 comentario
Stephen23
Stephen23 el 11 de Ag. de 2020
Editada: Stephen23 el 11 de Ag. de 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" ?

Iniciar sesión para comentar.

Respuesta aceptada

Stephen23
Stephen23 el 11 de Ag. de 2020
Editada: Stephen23 el 11 de Ag. de 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 comentario
ahmad Mohammadi
ahmad Mohammadi el 11 de Ag. de 2020
Editada: ahmad Mohammadi el 11 de Ag. de 2020
Thats great. I spent like 5 hours to reach a very bad coding. But, you saved me
Thanks,

Iniciar sesión para comentar.

Más respuestas (1)

Sudheer Bhimireddy
Sudheer Bhimireddy el 11 de Ag. de 2020
If the order is not important, look at sort function.

Categorías

Más información sobre Logical en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by