How to plot two curfeFit plots into one figure?

조회 수: 1 (최근 30일)
Jamina Kratz
Jamina Kratz 2021년 6월 9일
댓글: Jamina Kratz 2021년 6월 9일
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!

채택된 답변

EmirBeg
EmirBeg 2021년 6월 9일
편집: EmirBeg 2021년 6월 9일
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
EmirBeg
EmirBeg 2021년 6월 9일
편집: EmirBeg 2021년 6월 9일
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 2021년 6월 9일
Thank you, that did the trick. I did not realize that the figure command forced a new window! Now off to drawing pretty graphs.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Fit Postprocessing에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by