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.

 채택된 답변

Star Strider
Star Strider 2017년 12월 13일
편집: Star Strider 2017년 12월 13일

0 개 추천

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

Ezgi Ertunç
Ezgi Ertunç 2017년 12월 14일
Thank you for answer. My graph is changing when I run the Matlab.
Star Strider
Star Strider 2017년 12월 14일
My pleasure.
If my Answer helped you solve your problem, please Accept it!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2017년 12월 13일

0 개 추천

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

카테고리

태그

질문:

2017년 12월 13일

댓글:

2017년 12월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by