MATLAB Answers

How to plot two curfeFit plots into one figure?

1 view (last 30 days)
Jamina Kratz
Jamina Kratz on 9 Jun 2021
Commented: Jamina Kratz on 9 Jun 2021
Hello people,
I have two scripts generated by the curveFit app that I want to have displayed in the same figure. They are linear regressions for two near constant temperatures from the same continuous measurement. What I am trying right now is the following:
%the lowtemp/hightemp vectors are snippets from t_Al and T_Al.
t_Al_lowtemp = t_Al(1:47);
T_Al_lowtemp = T_Al(1:47);
t_Al_hightemp = t_Al(160:end);
T_Al_hightemp = T_Al(160:end);
createFit_hightemp(t_Al_hightemp, T_Al_hightemp); %first fit for the higher temperature
hold on
createFit_lowtemp(t_Al_lowtemp, T_Al_lowtemp); %second fit for the lower temperature
plot(t_Al,T_Al); %the full continuous measurement
hold of
The fits themselves look good but all plots are in seperate windows. I have not touched the scripts generated from curveFit and since they are all the same, I have left them out.
How would I go about getting them all in one figure?
Thank you in advance!

Accepted Answer

EmirBeg on 9 Jun 2021
Edited: EmirBeg on 9 Jun 2021
If you look at the Curve Fitting script you generated, you can see that both scripts try to plot the results at the end. Looks like this in the CurveFitting functions.
% Plot fit with data.
figure( 'Name', 'untitled fit 1' );
h = plot( fitresult, xData, yData );
legend( h, 'T_Al_hightemp vs. t_Al_hightemp', 'untitled fit 1', 'Location', 'NorthEast', 'Interpreter', 'none' );
% Label axes
xlabel( 't_Al_hightemp', 'Interpreter', 'none' );
ylabel( 'T_Al_hightemp', 'Interpreter', 'none' );
grid on
That's why your get multiple plots in seperate windows.
You can just erase these and plot it in your own code with tiledlayout and hold on / holf off.
Jamina Kratz
Jamina Kratz on 9 Jun 2021
Thank you, that did the trick. I did not realize that the figure command forced a new window! Now off to drawing pretty graphs.

Sign in to comment.

More Answers (0)




Community Treasure Hunt

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

Start Hunting!