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.

 채택된 답변

Stephen23
Stephen23 2016년 3월 9일
편집: Stephen23 2016년 3월 9일

0 개 추천

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

추가 답변 (2개)

Andrei Bobrov
Andrei Bobrov 2016년 3월 9일

0 개 추천

[~,~,c] = unique(x);
z = accumarray(c(:),y(:),[],@min);
Blotter678
Blotter678 2016년 3월 9일

0 개 추천

that worked great, Thanks guys!

카테고리

도움말 센터File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

태그

질문:

2016년 3월 9일

답변:

2016년 3월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by