Finding maximum value of y at some x

조회 수: 4 (최근 30일)
RAJAN PRASAD
RAJAN PRASAD 2016년 6월 17일
편집: Andrei Bobrov 2016년 6월 17일
I have a vector y=[6 8 10 9 11 31] x=[1 2 3 4 5 6] how to find at what x the first maximum value of y occured and the second maxima

답변 (3개)

Roger Stafford
Roger Stafford 2016년 6월 17일
[~,p] = sort(y,descend);
x2 = x(p(1:2)); % <-- x values at first and second maxima of y

KSSV
KSSV 2016년 6월 17일

Andrei Bobrov
Andrei Bobrov 2016년 6월 17일
편집: Andrei Bobrov 2016년 6월 17일
y=[6 8 11 10 31 9 11 31]
x=[3 9 4 1 23 3 2 7]
[a,~,c] = unique(y);
ii = accumarray(c(:),(1:numel(c))',[],@(x){x});
idx = ii([end,end-1]);
out = cellfun(@(a)x(a),idx,'un',0)

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by