How to move fitted plot along y axis

28 views (last 30 days)
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.

Accepted Answer

Dana
Dana on 24 Jun 2020
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 Comments
Dana
Dana on 24 Jun 2020
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.
Niklas Kurz
Niklas Kurz on 25 Jun 2020
Thank you for the clarification!

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!