How to plot two curfeFit plots into one figure?

1 visualización (últimos 30 días)
Jamina Kratz
Jamina Kratz el 9 de Jun. de 2021
Comentada: Jamina Kratz el 9 de Jun. de 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!

Respuesta aceptada

EmirBeg
EmirBeg el 9 de Jun. de 2021
Editada: EmirBeg el 9 de Jun. de 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 comentarios
EmirBeg
EmirBeg el 9 de Jun. de 2021
Editada: EmirBeg el 9 de Jun. de 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.
Of course you can also modify the legend and the names of the axis so it all fits together.
Jamina Kratz
Jamina Kratz el 9 de Jun. de 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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Smoothing en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by