how to create a contour for a fittype object?

2 views (last 30 days)
Hi,
i've fitted a surface for a scattered data using the following commands:
load('full_data.mat')
ft = fittype( 'poly11' );
opts = fitoptions( 'Method', 'LowessFit' );
opts.Normalize = 'on';
opts.Robust = 'LAR';
[fitresult, gof] = fit( [full_data(:,1), full_data(:,2)], full_data(:,3), ft, opts );
is it possible to plot the contours for this surface after i plotted the surface itself using the next command:
plot(fitresult, [full_data(:,1), full_data(:,2)], full_data(:,3) );
thank you for your help.

Accepted Answer

Mike Garrity
Mike Garrity on 8 Jul 2015
Edited: Mike Garrity on 8 Jul 2015
One simple way is to get the data from the surface that the plot method creates.
h = plot(fitresult, [full_data(:,1), full_data(:,2)], full_data(:,3) );
s = findobj(h,'Type','surface');
figure
contour(s.XData,s.YData,s.ZData)
The "cleaner" option would be to use the feval method. You need to pass in the XData and YData. Something like this:
load franke
T = table(x,y,z);
f = fit([T.x, T.y],T.z,'linearinterp');
[x,y]=meshgrid(linspace(500,3500,40),linspace(0,1,40));
z=feval(f,x,y);
contour(x,y,z)

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!