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.

 Respuesta aceptada

Stephen23
Stephen23 el 9 de Mzo. de 2016
Editada: Stephen23 el 9 de Mzo. de 2016

0 votos

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

Más respuestas (2)

Andrei Bobrov
Andrei Bobrov el 9 de Mzo. de 2016

0 votos

[~,~,c] = unique(x);
z = accumarray(c(:),y(:),[],@min);
Blotter678
Blotter678 el 9 de Mzo. de 2016

0 votos

that worked great, Thanks guys!

Categorías

Más información sobre Get Started with MATLAB en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 9 de Mzo. de 2016

Respondida:

el 9 de Mzo. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by