16 views (last 30 days)

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.

dpb
on 22 Aug 2020

Edited: dpb
on 24 Aug 2020

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');

dpb
on 24 Aug 2020

dpb
on 25 Aug 2020

Sure -- two ways to approach; both entail adding points to be evaluated over the extended range you want the plot drawn over.

- The fit object plot() routine:

newX=[newpoints1 X newpoints2];

hL1=plot(fitObject,newX,[nan(size(newpoints1)) data nan(size(newpoints1))]);

where newpoints1/2 are the locations outside the current range of independent variable you want to add...the X and the observed data vectors have to be same size here so must augment the data vector with NaN to match. As we've noted before, the NaN won't show on the plot.

2. The "traditional" plot() function:

hold on % altho should be already, to remind just in case

newY1=fitObject(newpoints1); % evaluate the fitted curve over

newY2=fitObject(newpoints2]; % the two new ranges wanted to add

hL3=plot(newpoints1,newY1); % add the two new ranges to the existing graph

hL4=plot(newpoints2,newY2); % first point in ranges should be existing line ends

Set linestyle, etc., as desired to match.

What isn't at all clear to me is how you get the second plot -- the range for the first covers the desired x-axis values, but the data points are scaled differently in the second and don't cover that range. Are those completely independent fits of a scaled variable in the second vis a vis the first, I guess?

Also, the first makes sense that the wider bell shape has lower peak and higher tails whereas the second shows the wider (blue) having both wider tails and being (slightly) taller at the peak. That wouldn't seem to normalize correctly to conserve area???

But, I have no idea what any of this is/means, but just looks strange to this dumb ol' nuclear engineer is all :)

Opportunities for recent engineering grads.

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

Start Hunting!
## 2 Comments

## Direct link to this comment

https://de.mathworks.com/matlabcentral/answers/583124-plotting-two-data-sets-using-the-curve-fitting-tool#comment_982112

⋮## Direct link to this comment

https://de.mathworks.com/matlabcentral/answers/583124-plotting-two-data-sets-using-the-curve-fitting-tool#comment_982112

## Direct link to this comment

https://de.mathworks.com/matlabcentral/answers/583124-plotting-two-data-sets-using-the-curve-fitting-tool#comment_982244

⋮## Direct link to this comment

https://de.mathworks.com/matlabcentral/answers/583124-plotting-two-data-sets-using-the-curve-fitting-tool#comment_982244

Sign in to comment.