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.

 Akzeptierte Antwort

Stephen23
Stephen23 am 9 Mär. 2016
Bearbeitet: Stephen23 am 9 Mär. 2016

0 Stimmen

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

Weitere Antworten (2)

Andrei Bobrov
Andrei Bobrov am 9 Mär. 2016

0 Stimmen

[~,~,c] = unique(x);
z = accumarray(c(:),y(:),[],@min);
Blotter678
Blotter678 am 9 Mär. 2016

0 Stimmen

that worked great, Thanks guys!

Kategorien

Mehr zu Get Started with MATLAB finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by