简体   繁体   English

在Matlab中使用2个更改变量创建3D图

[英]Creating a 3D Plot In Matlab With 2 Changing Variables

I am trying to create a 3D plot in Matlab. 我正在尝试在Matlab中创建3D图。

I have a very long problem starting with the data set of Y and Z. With much manipulation it boils down to a simple y/z problem 从Y和Z的数据集开始,我遇到了一个很长的问题。经过大量的操作,最终可以归结为一个简单的y / z问题。

y=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
z=[5, 10, 15, 20, 25, 30, 35, 40, 45, 50];


x=(y_new)/(z_new)

There is about 100 lines of equations manipulating y and z, to become two new variables y_new and z_new. 大约有100行方程式处理y和z,成为两个新变量y_new和z_new。 I would like to create a 3d plot of x,y,z. 我想创建一个x,y,z的3d图。 I would want an x value for (1,5) and (1,10), (2,5), (2,10) etc. 我想要一个(1,5)和(1,10),(2,5),(2,10)等的x值。

The way I have the problem setup is only using y=1 and z=5. 我设置问题的方式仅使用y = 1和z = 5。 I have been trying to use for-loops or while-loops for the past few hours but I am getting stuck. 在过去的几个小时中,我一直在尝试使用for循环或while循环,但是我一直陷于困境。

If someone can help me I would appreciate the time and effort! 如果有人可以帮助我,我将不胜感激。

You don't need to use a for loop. 您不需要使用for循环。 Instead, use the builtin function meshgrid() which is designed to solve exactly this problem. 相反,请使用旨在解决此问题的内置函数meshgrid()

Here's a tutorial from 'abbe' at MIT which details how to create a 3D plot of a function f(x,y) using meshgrid() . 这是麻省理工学院“ abbe”的教程 ,详细介绍了如何使用meshgrid()创建函数f(x,y)的3D图。

To quote the blurb: 引用blurb:

3D plotting 3D绘图

When you make a 3-dimensional plot, you usually have az variable that is a function of both x and y. 制作三维图时,通常会有一个z变量,该变量是x和y的函数。 When you want x and y to vary over some range, you need a matrix (rather than a vector) for x and y to get a complete domain that covers all the different combinations of those x and y values over some range. 当您希望x和y在某个范围内变化时,您需要一个矩阵(而不是向量)来获得x和y的完整域,该域覆盖某个范围内这些x和y值的所有不同组合。 A function called meshgrid will set up x and y matrixes like this for you. 名为meshgrid的函数将为您设置x和y矩阵。 The x matrix varies the x down rows and keeps it constant in columns, and the y matrix varies the y in columns and keeps it constant across rows, so you get all combinations of x and y if you use the two matrices. x矩阵改变x向下的行,并使其在列中保持不变,而y矩阵改变y的列,并使其在行中保持不变,因此,如果使用两个矩阵,则会得到x和y的所有组合。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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