How to move fitted plot along y axis

17 次查看(过去 30 天)
Hey, it's me again, this time I want to shift a fit I created with cftool:
[xData, yData] = prepareCurveData( Fqr, Prem );
% Set up fittype and options.
ft = fittype( 'a*atan(2*b*t/3.83^2-t^2)', 'independent', 't', 'dependent', 'y' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.StartPoint = [0.0496544303257421 0.902716109915281];
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts );
% Plot fit with data.
figure( 'Name', 'untitled fit 1' );
h = plot( fitresult, xData, yData,'x');
set(h,'LineWidth',2,'Markersize',7.5)
legend( h, 'Prem vs. Fqr', 'untitled fit 1', 'Location', 'NorthEast', 'Interpreter', 'none' );
% Label axes
xlabel( 'Fqr', 'Interpreter', 'none' );
ylabel( 'Prem', 'Interpreter', 'none' );
grid on
I manage to relcoate y values just by typing +pi/2 behind yData, but what about the fitted line? That's where I'm struggling.

采纳的回答

Dana
Dana 2020-6-24
Why not just shift up the raw y data?
[xData, tmp] = prepareCurveData( Fqr, Prem );
yData = tmp+pi/2; % shift up your y data values
Then everything else would be the same as you had.
  5 个评论
Dana
Dana 2020-6-24
When including the estimated constant c in your regression specification, you'll get the exact same shape of fitted curve whether or not you first add pi/2 to yData, the only difference is the curve will be shifted by a constant.
However, you won't generally get the same shape of fitted curve if you're comparing "with constant c, and with pi/2 added to yData" to "without constant c, and without pi/2 added to yData". In that case, only one of your specifications involves estimating a constant, so there's no reason to think you should get the same shape of curve. Hope that clarifies.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Linear and Nonlinear Regression 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by