Retrieving minimum values for parts of a matrix
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Azzi Abdelmalek
2016-5-17
编辑:Azzi Abdelmalek
2016-5-17
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Linear Programming and Mixed-Integer Linear Programming 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!