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 Related SolutionsMATLAB: How to make a smooth line using following data x=[3.3,3.3,3.2,3.2,3.1,3,2.9,2.9,2.8,2.8,2.7,2.6,2.6,2.5];y=[500,450,400,350,300,250,200,200,250,300,350,400,450,500];plot(x,y)n = 5 ; % can be changed p = polyfit(x,y,n);x1 = linspace(min(x),max(x));y1 = polyval(p,x1);hold onplot(x1,y1)hold off MATLAB: How do convert array x to array z If you want to convert the first value, whatever it may be, to 1, the second to 2, etc:>> x = [4 4 8 8 8 5 5 4 8 8 4];>> [~,ia,ic] = unique(x,'first');>> [~,ia] = sort(ia);>> z = ia(ic)z = 1 1 2 2 2 3 3 1 2 2 1 Related QuestionHow can i find row position for minimum value that changes every cycle. each cycle has 100 data points( 100*1 matrix).Surf plot using meshgridRearrange matix in ascending order using one column as index!Can anybody explain the commented line of the codeFind unique values in a sequence containing at least 3 elementsComparing all the elements of an array with all the elements of another array
Best Answer