Retrieving minimum values for parts of a matrix
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Isma_gp
el 17 de Mayo de 2016
Hi, I have a matrix containing different rows with values for several years. I need to retrieve the minimum value corresponding to each year. For example: A=[ 1958 2; 1958 3; 1959 4; 1959 5; 1959 6 ] The result matrix that I need would be: B=[ 1958 2; 1959 4 ]
Could you please help with this? Thanks
0 comentarios
Respuesta aceptada
Azzi Abdelmalek
el 17 de Mayo de 2016
Editada: Azzi Abdelmalek
el 17 de Mayo de 2016
A=[ 1958 2; 1958 3; 1959 4; 1959 5; 1959 6 ]
[ii,jj,kk]=unique(A(:,1))
out=[ii accumarray(kk,(1:numel(kk))',[],@(x) min(A(x,2)))]
0 comentarios
Más respuestas (1)
Matt J
el 17 de Mayo de 2016
Editada: Matt J
el 17 de Mayo de 2016
[i,~,s]=find( accumarray(A(:,1), A(:,2),[],@min ) );
B=[i,s]
Ver también
Categorías
Más información sobre Problem-Based Optimization Setup 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!