How can I plot slope including maximum peaks?

Hello, How can I plot slope including peaks point? It should look like exp. I tried envelope but It does not work for my code.
Thank you.

 采纳的回答

If you have the Signal Processing Toolbox, use the findpeaks function to define the peaks and their locations. You can then use those values directly in your exponential regression.
EDIT
Try this:
y = [12 14 2 8 9 4 6 7 9 5 6];
x = 1:length(y);
ym = mean(y);
yz = y - ym; % Create Symmetry About Mean
[pospks, poslocs] = findpeaks(yz); % Positive Peaks & Locations
[negpks, neglocs] = findpeaks(-yz); % Negative Peaks & Locations
pkvct = [pospks negpks]; % Combine In One Vector FOr Sorting
[locs,idx] = sort([poslocs neglocs]); % Sort
pks = pkvct(idx);
objfcn = @(b,x) b(1).*exp(b(2).*x); % Exponential Objective Function
[B,resnorm] = fminsearch(@(b) norm(pks - objfcn(b,locs)), rand(2,1)); % Fit Data (EStimate Parameters)
figure(1)
plot(x, y, '-g')
hold on
% plot(locs, pks+ym, 'pg')
plot(locs, objfcn(B,locs)+ym, '-r')
hold off
text(5, 13, sprintf('y(x) = %.3f + e^{%.3f\\cdotx} + %.3f', B, ym))

2 个评论

Thank you for answer. My graph is changing when I run the Matlab.
My pleasure.
If my Answer helped you solve your problem, please Accept it!

请先登录,再进行评论。

更多回答(1 个)

Why would you try envelope()? diff() would give the slope
slopes = diff(y)

标签

Community Treasure Hunt

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

Start Hunting!

Translated by