# Isolate horizonal part of curve

조회 수: 2(최근 30일)
MichailM 2023년 1월 31일
댓글: Image Analyst 2023년 1월 31일
I have the data in the graph below (blue dotted line). I have fitted a curve (red line). How can I isolate the flat/horizontal part?
Code example:
close all;
clear all;
clc;
ft = fittype('(a.*x.^b)',...
'dependent',{'y'},'independent',{'x'},...
'coefficients',{'a','b'});
f = fit(dataX,dataY,ft,'StartPoint',[600 -1]);
coeffvals = coeffvalues(f);
figure
plot(dataX,dataY,'-ob')
hold on
plot(dataX,f(dataX),'-r')
legend('Actucal data','Fitted')
xlabel('dataX')
ylabel('dataY')
The ExampleData file is also attached.
##### 댓글 수: 3표시숨기기 이전 댓글 수: 2
Star Strider 2023년 1월 31일
Plotting it on a loglog scale produces a straight line (as would be expected from a power relation) —
dataX = LD.dataX;
dataY = LD.dataY;
ft = fittype('(a.*x.^b)',...
'dependent',{'y'},'independent',{'x'},...
'coefficients',{'a','b'});
f = fit(dataX,dataY,ft,'StartPoint',[600 -1])
f =
General model: f(x) = (a.*x.^b) Coefficients (with 95% confidence bounds): a = 600.4 (561.2, 639.5) b = -1.038 (-1.041, -1.035)
coeffvals = coeffvalues(f);
figure
loglog(dataX,dataY,'-ob')
hold on
plot(dataX,f(dataX),'-r')
legend('Actual data','Fitted')
xlabel('dataX')
ylabel('dataY')
.

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

### 답변(4개)

John D'Errico 2023년 1월 31일
What part of this curve is horizontal?
syms x
F = exp(-10*x)
F =
fplot(F,[0,3])
Well, clearly, ithe horizontal part lies above x==0.5.
fplot(F,[0.5,3.5])
Oh wait. It must start above x==1.
fplot(F,[1,4])
Wow. That is strange. It must start above x==1.5.
fplot(F,[1.5,4.5])
I think I'm gonna get it right soon. It DEFINITELY starts at x==2.
fplot(F,[2,5])
This is really, really strange.
Or, maybe, just maybe, there is NO horizontal part of the curve. Wherever you look, the curve has EXACTLY the same shape.
##### 댓글 수: 0표시숨기기 이전 댓글 수: -1

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

Walter Roberson 2023년 1월 31일
Declare your horizontal cutoff to be the place where abs() of the gradient is less than some threshold. If necessary, low-pass filter the data first (to remove experimental noise)
##### 댓글 수: 0표시숨기기 이전 댓글 수: -1

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

Image Analyst 2023년 1월 31일
Maybe adjust the axis to start and end wherever you want, like
xlim([0.5e-6, 5e-6]);
but like John said, there is no flat part so you just have to make some judgment about where you think the flat part starts.
##### 댓글 수: 0표시숨기기 이전 댓글 수: -1

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

MichailM 2023년 1월 31일
It seems that my description of the flat/horizontal part caused some sort of confusion with regards to the strict definition of it. dataY shows an abrupt decrease for the the very early values of dataX which fits well to the behavior of the power function. From a point an after, that decrease becomes sort of linear with superimposed experimental noise as Walter mentioned.
I will need to detect the part where the curve in the first post becomes sort of linear, after it has experienced the abrupt decrease. I hope that explains things somehow better. Apologies for the confusion.
##### 댓글 수: 1표시숨기기 없음
Image Analyst 2023년 1월 31일
You can try my piecewise linear demo, attached.
My attached demo does the "Novice Method" above. It looks like you're using the "Expert Method" above.
Or you can use the triangle method, also attached.

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

### 범주

Find more on Get Started with Curve Fitting Toolbox in Help Center and File Exchange

R2022b

### Community Treasure Hunt

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

Start Hunting!

Translated by