[英]Plot x=y plane in MATLAB
I fail to think how should I proceed for plotting x=y
plane withing a 2x2x2 space. 我没想到我应该如何绘制具有2x2x2空间的x=y
平面。
I create a 2x2 meshgrid 我创建了一个2x2网格
[X,Y]=meshgrid(-1:0.1:1,-1:0.1:1);
then I come to define Z
- I get stuck 然后我来定义Z
- 我被卡住了
My thoughts go like this 我的想法是这样的
surf
function.. and the dimensions of X, Y, Z must match. Right?). 我需要为Z创建一个21x21数组(我使用surf
功能..并且X,Y,Z的尺寸必须匹配。对吧?)。 x==y
我只需要填充x==y
的Z值 x==y
Z will vary -1:0.1:1
.. Does This require that I iterate again and again on the x==y
and keep drawing Z with values from -1:0.1:1
? 现在对于每个这样的点,即x==y
Z将变化-1:0.1:1
..这是否需要我在x==y
上一次又一次地迭代并且使用-1:0.1:1
值继续绘制Z? Am I going the right way about plotting this plane? 我是否正确地绘制这架飞机? Kindly help. 请帮助。
You simply need to define X
and Z
, Y
is equal to X
by definition: 您只需要定义X
和Z
, Y
根据定义等于X
:
[X Z] = meshgrid(-1:.1:1,-1:.1:1);
figure;
surf(X,X,Z);xlabel('x');ylabel('y');zlabel('z');
Results with 结果用
You are actually trying to do something two dimensional in a 3 dimensional setting. 你实际上是想在三维设置中做二维的事情。
A bit unintuitive, but that does not mean it can't be done, for example: 有点不直观,但这并不意味着它无法完成,例如:
[X,Y]=meshgrid(-1:0.1:1,-1:0.1:1);
Z = zeros(size(X)); % Perhaps you want NaN rather than zeros
idx = X==Y;
Z(idx)=X(idx).^2+Y(idx) % Of course identical to X(idx).^2+X(idx)
surf(Z)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.