简体   繁体   English

在MATLAB中绘制x = y平面

[英]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 我的想法是这样的

  1. I need to create a 21x21 array for Z ( I use surf function.. and the dimensions of X, Y, Z must match. Right?). 我需要为Z创建一个21x21数组(我使用surf功能..并且X,Y,Z的尺寸必须匹配。对吧?)。
  2. I need to populate only those values of Z that follow x==y 我只需要填充x==y的Z值
  3. Now for each such point ie 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: 您只需要定义XZY根据定义等于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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM