Effacer les filtres
Effacer les filtres

Contour Plotting in Surface Fitting Tool

3 vues (au cours des 30 derniers jours)
lynniz
lynniz le 24 Jan 2011
Hi All,
I used the surface fitting tool to generate a contour plot on some scattered data (vector x, vector y, and vector z). I would like to know if there are any ways to plot only the specified contour levels and also label those contour levels just like the contour function.
Please let me know if there are any alternatives to do contour plotting using scattered data. I have tried the TriScatteredInterp method, but the contour plot did not make any sense.
Any help will be greatly appreciated!
Thanks,
Lynniz

Réponse acceptée

Andreas Goser
Andreas Goser le 25 Jan 2011
If I understand your question correctly, this can be achieved by exporting the data and creating a new contour plot that can be modified. Supporting information:
http://www.mathworks.com/support/solutions/en/data/1-AMH9HS/index.html

Plus de réponses (2)

Richard Willey
Richard Willey le 27 Jan 2011
Here's some code that should help get you started. Most of this code is framing the problem. The section dealing with the customer contours is all the way at the bottom.
%% Generate a reference model using the peaks function
% Use a halton set to generate some random x, y data P = haltonset( 2 ); P = scramble( P, 'RR2' ); X = net( P, 30);
x = ((X(:,1)) * 6) - 3; y = (X(:,2) * 6) - 3;
% Use the peaks function to generate a z vector
z = peaks(x,y); z = z + .5 * randn(30,1);
% Use the fit command to create a fit object
ft = fittype( 'a*(1-x).^2.*exp(-(x.^2) - (y+1).^2) + b*(x/5 - x.^3 - y.^5).*exp(-x.^2-y.^2) + c*exp(-(x+1).^2 - y.^2)', 'indep', {'x', 'y'}, 'depend', 'z' ); opts = fitoptions( ft ); opts.Display = 'Off'; opts.Lower = [-Inf -Inf -Inf]; opts.StartPoint = [0.698493238453756 0.502175213611344 0.687201121067495]; opts.Upper = [Inf Inf Inf]; opts.Weights = zeros(1,0); [fittedmodel, gof] = fit( [x, y], z, ft, opts );
%% Problem Definition
% A 2D lookup table is an approximation of a response with points defined % by a row vector and column vector of containing M and N elements, % respectively. For example, we can approximate our model using a uniform % 13 x 13 grid
a = -3; b = 3; x = linspace(a,b,13); y = linspace(a,b,13); [X,Y] = meshgrid(x,y);
plot(fittedmodel, 'style','contour') hold on scatter(X(:),Y(:),'k','filled');
%% Generate a Fit Object to describe our 13 x 13 uniform table
Z = fittedmodel(X,Y); fitObj = fit([X(:), Y(:)], Z(:), 'linearinterp')
hold off plot(fitObj)
%% Visually compare the two surfaces
% Generate a reference grid to evaluate the two surfaces xr = linspace(a,b,100); yr = linspace(a,b,100); [Xr, Yr] = meshgrid(xr,yr);
% Calculate the difference between the two surfaces resid = fittedmodel(Xr(:), Yr(:)) - fitObj(Xr(:), Yr(:));
% Create a Fit Object describing the residuals Diff_Contour = fit([Xr(:), Yr(:)], resid, 'linearinterp');
% Generate a contour plot of the residuals figure('Numbertitle', 'off', 'name', 'Contour Map of Residuals: Uniform Grid')
xlim = [-3, 3]; ylim = [-3, 3]; obj = Diff_Contour;
[xi, yi] = meshgrid( ... linspace( xlim(1), xlim(2), 49 ), ... linspace( ylim(1), ylim(2), 51 ) ); zi = feval( obj, xi, yi );
[~, h] = contourf( xi, yi, zi, 21 );
grid on colorbar caxis ([-1.3 1.3])

lynniz
lynniz le 3 Fév 2011
Thank you very much for your help!

Catégories

En savoir plus sur Contour Plots dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by