尝试使用MATLAB绘制z = x + y时图形不正确 [英] Incorrect graph when trying to plot z = x + y with MATLAB
问题描述
我正在尝试在MATLAB中绘制3D曲面,并且我使用了 的错误图 我很确定上图中的图形不是 不过,我发现脚本太简单了,看不到任何错误.谁能指出我忽略了什么地方?谢谢. 您生成3D坐标的语法是正确的.您对 执行此操作时,您会获得此表面.请注意,生成的图形是使用MATLAB R2013a绘制的,因此显示的颜色图不是R2014b及更高版本中可用的parula颜色图,但是表面将是您要查找的正确的颜色图:>
...现在为什么需要分开 您需要将 I am attempting to plot 3D surfaces in MATLAB, and I made use of I wrote a very simple three line script that I believed would produce the surface z = x + y and it is as follows: From what I understand, line 1 produces all combinations of (x,y) coordinates evenly spaced from 0 to 10. Then line 2 just applies the formula But I got the following "thing" as output: I'm pretty sure the graph in the above picture is not Still, I find the script too simple and couldn't see anything wrong with it. Could anyone point out where I overlooked something? Thank you. Your syntax for generating the 3D coordinates is right. Your call to When you do that, you get this surface. Take note that the figure generated was using MATLAB R2013a, so the colour map shown is not the parula colour map that is available as of R2014b and up, but the surface will be the right one that is what you're looking for: ... now why do you need to separate your You need to separate the 这篇关于尝试使用MATLAB绘制z = x + y时图形不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!meshgrid
,类似于MATLAB教程在这里说的内容:
z = x + y
,而且我不知道为什么没有两个轴达到最大值10.surf
的呼叫不正确.您实际需要做的是将x
,y
和z
分为三个单独的参数:surf(x,y,z);
x
,y
和z
点来创建曲面?原因是因为执行[x,y,z]
意味着您正在级联 x
,y
和z
坐标为单个2D信号,所以这是什么事实是您正在创建一个10 x 30的2D信号.使用此单个2D数组调用surf
会自动假定x
值的范围是1到30,而y
值的范围是1到10,并且是跨越surf
图的轴的2D值网格以及所显示的z
值,其中z
值源自之前创建的级联矩阵.如果查看生成的图,可以看到x
值从1到30,显然不是您想要的.x
,y
和z
值分开以达到所需的平面.meshgrid
, similar to what the MATLAB tutorials said here: http://www.mathworks.com/help/matlab/ref/meshgrid.html[x , y] = meshgrid( linspace( 0 , 10 , 10 ) , linspace( 0 , 10 , 10 ) );
z = x + y;
surf( [ x , y , z] );
z = x + y
to that exhaustive list of combinations. Then line 3 just plots all the (x, y, z)
points.z = x + y
, and I have no clue why there aren't two axes going up to maximum value 10. surf
is incorrect. What you actually need to do is separate x
, y
and z
into three separate parameters:surf(x,y,z);
x
, y
and z
points to create the surface? The reason why is because doing [x,y,z]
means that you are concatenating the x
, y
and z
coordinates into a single 2D signal, and so what's happening is that you are creating a 2D signal that is 10 x 30. Calling surf
with this single 2D array automatically assumes that the x
values span from 1 to 30 and the y
values span from 1 to 10 and those are the 2D grid of values that span the axis of your surf
plot in conjunction with the z
values shown, where the z
values originate from the concatenated matrix created earlier. If you look at the plot you generated, you can see the x
values are spanning from 1 to 30, and that's obviously not what you want.x
, y
and z
values to achieve the desired plane.