How can I get the slope of the peak?

6 ビュー (過去 30 日間)
tzu-hsin yang
tzu-hsin yang 2020 年 9 月 21 日
コメント済み: tzu-hsin yang 2020 年 9 月 23 日
如何獲得峰的斜率?
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)
  1 件のコメント
tzu-hsin yang
tzu-hsin yang 2020 年 9 月 23 日
Thank you very much ! This really help me a lot.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDescriptive Statistics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by