How do I plot the level sets of one function projected onto a surface, or how do I project contours onto a surface object in MATLAB?
18 次查看(过去 30 天)
显示 更早的评论
I would like to plot the level sets of a function onto a surface. I have the equation defining the surface, as well as the set levels in term of the three variables, [X, Y, Z]
采纳的回答
MathWorks Support Team
2009-6-27
The ability to automatically have contour levels projected onto a surface is not available directly in MATLAB.
To work around this issue, read the commented example below:
The following example demonstrates the plotting of level sets of a function onto the surface as defined by another function, all in three variables.
[X,Y] = meshgrid([-2:.25:2]);
% Plotting the Z-values of the function whose level sets have
% to be determined
Z = X.*exp(-X.^2-Y.^2);
% Plotting the Z-values of the function on which the level
% sets have to be projected
Z1 = X.^2+Y.^2;
% Plot your contour
[cm,c]=contour(X,Y,Z,30);
% Plot the surface on which the level sets have to be projected
s=surface(X,Y,Z1,'EdgeColor',[.8 .8 .8],'FaceColor','none')
% Get the handle to the children i.e the contour lines of the contour
cv=get(c,'children');
% Extract the (X,Y) for each of the contours and recalculate the
% Z-coordinates on the surface on which to be projected.
for i=1:length(cv)
cc = cv(i);
xd=get(cc,'XData');
yd=get(cc,'Ydata');
zd=xd.^2+yd.^2;
set(cc,'Zdata',zd);
end
grid off
view(-15,25)
colormap cool
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Contour Plots 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!