How to plot two curfeFit plots into one figure?
1 view (last 30 days)
Show older comments
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!
0 Comments
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.
3 Comments
EmirBeg
on 9 Jun 2021
Edited: EmirBeg
on 9 Jun 2021
I just realized it would be even easier if you just erase the first line of the plot command in the function:
figure( 'Name', 'untitled fit 1' ); %erase this
This creates a new figure if you call the function but you don't want two figures.
Now you can plot both fits in one plot like this:
AL_H = createFit_hightemp(t_Al_hightemp, T_Al_hightemp);
hold on;
AL_L = createFit_lowtemp(t_Al_lowtemp, T_Al_lowtemp);
hold off;
You don't need to use plot() in your code now and it should work now.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/647375/image.jpeg)
Of course you can also modify the legend and the names of the axis so it all fits together.
More Answers (0)
See Also
Categories
Find more on Smoothing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!