How can I get the slope of the peak?

8 次查看(过去 30 天)
如何獲得峰的斜率?
I would like to know the slpoe of the orange line( picture shows below)
Thank you!
data=xlsread('data.xlsx',1,'A:B'); %import data,column A means the frame number; column B means the intensity%
frame=data(:,1);
time=data(:,1)./25;
avgI=data(:,2);
B=transpose(avgI); %to make column into row%
[TF,S1,S2]=ischange(B,'linear','Threshold',200);
segline = S1.*(1:3012) + S2; % to get a linear line that fit the peak%
plot(time,B,time,segline)
legend('Data','Linear Regime')
xlabel('Time / s')
ylabel('Mean gray value')
%%
  2 个评论
Image Analyst
Image Analyst 2020-9-21
The slope at the peak itself is zero. Do you mean the slope from x=54 to the peak at x=80? Or the slope from x=80 to x=100?
tzu-hsin yang
tzu-hsin yang 2020-9-21
The slope from x=54 to x=63, the slope oh the orange line.

请先登录,再进行评论。

采纳的回答

Image Analyst
Image Analyst 2020-9-21
Try this:
% Your existing code:
data=xlsread('data.xlsx',1,'A:B'); %import data,column A means the frame number; column B means the intensity%
frame=data(:,1);
time=data(:,1)./25;
avgI=data(:,2);
B=transpose(avgI); %to make column into row%
[TF,S1,S2]=ischange(B,'linear','Threshold',200);
segline = S1.*(1:3012) + S2; % to get a linear line that fit the peak%
plot(time,B,time,segline)
legend('Data','Linear Regime')
xlabel('Time / s')
ylabel('Mean gray value')
%% New Code
x = time;
y = B;
% Get index for section from time = 54 to 63
index1 = find(x > 54, 1, 'first');
index2 = find(x > 63, 1, 'first');
% Compute slope in that section:
coefficients = polyfit(x(index1:index2), y(index1:index2), 1)
yFit = polyval(coefficients, x(index1:index2));
hold on;
plot(x(index1:index2), yFit, 'r-', 'LineWidth', 2);
caption = sprintf('Slope from time = %f to time = %f is %f', x(index1), x(index2), slope)
title(caption, 'FontSize', 20)
slope = coefficients(1)

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by