【发布时间】:2019-03-13 20:02:20
【问题描述】:
我正在尝试学习如何绘制具有分段条件的曲面图,但我自己无法弄清楚。这是我迄今为止所拥有的:
[X,Y] = meshgrid(-10:0.1:10,0:.1:4);
Z = ((X.^2)/100).*(1-(((Y-2).^2)/4));
C = X.*Y;
surf(X,Y,Z,C)
colorbar
xlabel('X')
ylabel('Y')
zlabel('Z')
%The block of code above looks great for what I need initially
% Now the commented code below is what I was working on and
% I feel that I have defined the piece-wise function correctly
% but cannot plot it properly
% syms p(Y)
% p(Y) = piecewise(Y<2, 1, Y>2, -1)
% [X,Y] = meshgrid(-10:0.1:10,0:.1:4);
% Z = zeros(size(X));
% Z = p(Y).*(((X.^2)/100).*(1-(((Y-2).^2)/4)));
% C = X.*Y;
% surf(X,Y,Z,C)
% colorbar
第二个块在某种程度上基于如何在枫树中完成。然而,根据 MATLAB 文档,这似乎是尝试了细微变化后最正确的版本。
【问题讨论】:
标签: matlab plot matlab-figure surface piecewise