How can I get the slope of the peak?

6 Ansichten (letzte 30 Tage)
tzu-hsin yang
tzu-hsin yang am 21 Sep. 2020
Kommentiert: tzu-hsin yang am 23 Sep. 2020
如何獲得峰的斜率?
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 Kommentare
Image Analyst
Image Analyst am 21 Sep. 2020
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 am 21 Sep. 2020
The slope from x=54 to x=63, the slope oh the orange line.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Image Analyst
Image Analyst am 21 Sep. 2020
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)
  1 Kommentar
tzu-hsin yang
tzu-hsin yang am 23 Sep. 2020
Thank you very much ! This really help me a lot.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by