Finding maximum value of y at some x
1 回表示 (過去 30 日間)
古いコメントを表示
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
0 件のコメント
回答 (3 件)
Roger Stafford
2016 年 6 月 17 日
[~,p] = sort(y,’descend’);
x2 = x(p(1:2)); % <-- x values at first and second maxima of y
0 件のコメント
KSSV
2016 年 6 月 17 日
doc findpeaks()..... Check the link for further explanation: http://in.mathworks.com/matlabcentral/answers/44227-finding-local-minimums-maximums-for-a-set-of-data
0 件のコメント
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)
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!