Isolate horizonal part of curve
4 次查看(过去 30 天)
显示 更早的评论
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?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1279080/image.png)
Code example:
close all;
clear all;
clc;
load('ExampleData');
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 个评论
Star Strider
2023-1-31
Plotting it on a loglog scale produces a straight line (as would be expected from a power relation) —
LD = load(websave('ExampleData','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1279075/ExampleData.mat'));
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])
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)
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 个评论
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 个评论
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 个评论
MichailM
2023-1-31
1 个评论
Image Analyst
2023-1-31
You can try my piecewise linear demo, attached.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1279595/image.png)
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spline Postprocessing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!