MATLAB: Minimum of unique values

MATLABvector

I am trying to find the minimum of vector y=[ 1 2 4 3 9 7] which corresponds to vector x= [100 100 200 200 300 300] so that the result is z=[1 3 7]
what I need is the minimum of each unique x value.

Best Answer

You can use unique and accumarray:
>> x = [100 100 200 200 300 300];
>> y = [ 1 2 4 3 9 7];
>> [~,~,ic] = unique(x,'stable');
>> z = accumarray(ic(:),y,[],@min)
z =
1
3
7