MATLAB: Plotting two data sets using the Curve Fitting Tool

curve fitting

Hi,
I was wondering is it possible two fit two different data sets in the same plot? The data sets are scatter plots and I have fitted a 4th polynomial through both sets seen attached. I would like to combine the two plots into one. Is there anyway to do so? I tried using the hold function but it did not work.

Best Answer

Well, the old-fashioned way if all you wanted was the coefficients would be to use polyfit and polyval ...but since you have the TB, why not just use fit and get the statistics and builtin behavior automagically?
fithealthy4=fit(PIVlabLocation1.VarName38,PIVlabLocation1.VarName39,'poly4');
fitunhealthy4=fit(G0801location1.AVERAGE,G0801location1.VarName21,'poly4');
hLH=plot(fithealthy4PIVlabLocation1.VarName38,PIVlabLocation1.VarName39);
hold on
hLUH=plot(G0801location1.AVERAGE,G0801location1.VarName21);
set(hLH,{'color'},{'b'}) % healthy blue
set(hLUH,{'color'},{'r'}) % unhealthy red
vals=[{'o';'o'} get([hLH(1) hLUH(1)],{'color'})]; % marker circle, same color as line face color
set([hLH(1) hlUH(1)],{'Marker','MarkerFaceColor'},vals)
xlabel('Y*')
ylabel('U*')
title('Comparison of healthy and unhealthy data')
hLg=legend([hLH(2),hLUH(2)],'Healthy','Unhealthy','Location','northeast');