gpt4 book ai didi

matlab - 为什么我的 Z 限制没有设置,即使我指定了它?

转载 作者:太空宇宙 更新时间:2023-11-03 20:32:32 24 4
gpt4 key购买 nike

请参阅下面的代码:

x = linspace(-2*pi,2*pi,100);
y = linspace(-2*pi,2*pi,100);
[X,Y] = meshgrid(x,y);

for t = linspace(0,2*pi,400);
Z = sin(sqrt(X.^2 + Y.^2 + t)) ./ (X.^2 + Y.^2 + t);
figure(1); surf(X,Y,Z);
pause(0.01)
surf(X,Y,Z);
az = 90;
el = 25;
figure(2);view(az,el);
xlim([-10,10]);
ylim([-10,10]);
zlim([-1,1]);
end

为什么即使设置为 [-1 1] z 限制仍然在不断变化?

最佳答案

你的问题是你每次调用 surf 时都会重新创建整个情节在你的循环中,从而丢弃你之前对 Axis 限制等所做的任何更改。当动画图时,如果你使用 set 会更有效(并且更容易控制 Axis 设置)更新graphics objects而不是完全复制它们,如图所示 here .

这里有一个更好的方法来创建你想要的动画:

% Initialize data:
x = linspace(-2*pi, 2*pi, 100);
y = linspace(-2*pi, 2*pi, 100);
[X, Y] = meshgrid(x, y);
Z = sin(sqrt(X.^2 + Y.^2)) ./ (X.^2 + Y.^2);

% Create plot objects and set axes settings:
hSurf = surf(X, Y, Z);
view(90, 25);
xlim([-10 10]);
ylim([-10 10]);
zlim([-1 1]);

% The animation loop:
for t = linspace(0, 2*pi, 400)
Z = sin(sqrt(X.^2 + Y.^2 + t)) ./ (X.^2 + Y.^2 + t); % Recalculate Z
set(hSurf, 'ZData', Z); % Update surface Z data
pause(0.01); % Pause/refresh plot
end

关于matlab - 为什么我的 Z 限制没有设置,即使我指定了它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47044064/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com