How to move fitted plot along y axis

30 visualizaciones (últimos 30 días)
Niklas Kurz
Niklas Kurz el 24 de Jun. de 2020
Comentada: Niklas Kurz el 25 de Jun. de 2020
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.

Respuesta aceptada

Dana
Dana el 24 de Jun. de 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 comentarios
Dana
Dana el 24 de Jun. de 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 el 25 de Jun. de 2020
Thank you for the clarification!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Linear and Nonlinear Regression en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by