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.
댓글 수: 0
채택된 답변
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
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 Center 및 File Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!