Hi all,
I have been using matlab's curve fitter app to fit an exponential curve to the number of active cases at a certain day. The function was generated with matlab's code generator and does this just fine.
I would like to automate how the labels are assigned on the Explonential Curve subplot and the Residuals Subplot so on each subplot the x and y labels are assigned from the createFit(day, cases) input variables.
So if I wanted to fit a curve to the number of new cases per day (new_cases), i would call createFit(day,new_cases) the x and y label of each subplot would be the name of the respective input variable, day and new_cases, rather then changing the label inside the function.
function [fitresult, gof] = createFit(day, cases)
[xData, yData] = prepareCurveData( day, cases );
ft = fittype( 'exp1' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.StartPoint = [28.0415018660604 0.202270403686444];
[fitresult, gof] = fit( xData, yData, ft, opts );
figure( 'Name', 'Exponential_Curve_Corona' );
subplot( 2, 1, 1 );
h = plot( fitresult, xData, yData );
legend( h, 'New Cases vs. day', 'Exponential_Curve_Corona', 'Location', 'Best', 'Interpreter', 'none' );
xlabel('day', 'Interpreter', 'none' );
ylabel('cases', 'Interpreter', 'none' );
xlim([min(xData) max(xData)])
grid on
subplot( 2, 1, 2 );
h = plot( fitresult, xData, yData, 'residuals' );
legend( h, 'Exponential_Curve_Corona - residuals', 'Zero Line', 'Location', 'Best', 'Interpreter', 'none' );
xlabel('day', 'Interpreter', 'none' );
ylabel('cases', 'Interpreter', 'none' );
xlim([min(xData) (max(xData)+0.1)])
grid on
end
Thank you in advance for any suggestions :)

 채택된 답변

Subhamoy Saha
Subhamoy Saha 2020년 3월 25일

1 개 추천

Use the following lines.
xlabel(['day-', inputname(1)], 'Interpreter', 'none' );
ylabel(['cases-', inputname(2)], 'Interpreter', 'none' );
Note that inputname(1) or inputname(2) will be empty if the input was an expression.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Fit Postprocessing에 대해 자세히 알아보기

제품

릴리스

R2019b

태그

질문:

2020년 3월 25일

댓글:

2020년 3월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by