MATLAB: Comparing 2 columns of a matrix

MATLABmatrix

I want to compare 2 columns of my matrix as shown below:
mat.png
For example, I have the number 4 in the first column occurring thrice. I need to compare it's corresponding values in column 2 and obtain the minimum value among them. I then need to store that value in another matrix.
Could someone suggest me a way to get this desired result.
Thanks and regards

Best Answer

Try this (using the accumarray (link) function):
A = [randi(10, 20, 1) rand(20,1)] % Create Data
[A1u,~,idx] = unique(A(:,1)); % Unique Values & Indices
MinVals = accumarray(idx, A(:,2), [], @(x)min(x)); % Find Minimum Of Each
Result = [A1u, MinVals] % Desired Result
Use your own matrix for ‘A’.