如何在 MatLab 中创建图形?

How to create the figure in MatLab?

我知道我应该使用函数 slice 或者不是吗?简单地说,如果我有 z 的功能,我不明白 V 是如何使用的?

我不认为有built-in函数可以画出这样的情节,而slice函数肯定不是那个。但是,您可以通过使用 patch:

绘制多个单独的补丁来获得所需的结果

plots one or more filled polygonal regions using the elements of X and Y as the coordinates for each vertex. patch connects the vertices in the order that you specify them. To create one polygon, specify X and Y as vectors. To create multiple polygons, specify X and Y (and Z) as matrices where each column corresponds to a polygon.

nS = 19; % number of slices
ygv = linspace(-2, 2, nS); % position of slices on Y axis
xgv = linspace(-2, 2, 100); % position of points on each curve
[X, Y] = meshgrid(xgv, ygv);
Z = X.^2+Y.^2;
% adding two points with z=0 at both ends of each curve
X = [X(:, 1), X, X(:, end)];
Y = [Y(:, 1), Y, Y(:, end)];
Z = [zeros(nS, 1), Z, zeros(nS, 1)];
patch('Xdata', X', 'Ydata', Y', 'Zdata', Z', 'facecolor', [1 1 1]*0.9);
xlabel('x'), ylabel('y'), zlabel('z')
title('z=x^2+y^2')
grid on
view(3)