matlab函数绘图三维(宏记软件四)

matlab函数绘图三维(宏记软件四)(1)

分享兴趣,传播快乐,增长见闻,留下美好。

亲爱的您,

这里是LearingYard学苑!

今天小编为大家带来Matlab三维绘图及gtext函数.

欢迎您的用心访问!

本期推文阅读时长大约5分钟,请您耐心阅读。

Share interest, spread happiness,

increase knowledge, and leave beautiful.

Dear you.

This is the LearingYard Academy!

Today, the editor brings Matlab 3D drawing and gtext function.

Welcome your visit!

The reading time of this tweet is about 5 minutes, please read it with patience.

大家好,本期推文将介绍几种三维绘图的方式和gtext函数,一起来看。

Hello everyone, this tweet will introduce several 3D drawing methods and gtext functions, let's take a look.

1.圆柱图

Matlab里面一般用cylinder创建圆柱数据,用surf 或 mesh 函数绘制出三维图。绘制方法如下:

左边代码为:

t = 0:pi/20:2*pi;

r = 4 sin(t);

[X,Y,Z] = cylinder(r);

surf(X,Y,Z)

xlabel('x')

ylabel('y')

zlabel('z')

代码含义为t在0π—2π中每隔20分之一π取一点,然后对半径r赋值:r=4 sin(t),然后以原点为底面中心绘制圆柱,并标上X,Y,Z坐标轴。

1. Cylindrical diagram

In Matlab, cylinder is generally used to create cylinder data, and surf or mesh functions are used to draw three-dimensional graphs. The drawing method is as follows:

The code on the left is:

t = 0:pi/20:2*pi;

r = 4 sin(t);

[X,Y,Z] = cylinder(r);

surf(X,Y,Z)

xlabel('x')

ylabel('y')

zlabel('z')

The meaning of the code is that t takes a point every 1/20 of π in 0π—2π, and then assigns a value to the radius r: r=4 sin(t), then draws a cylinder with the origin as the center of the bottom surface, and marks X, Y, Z coordinate axis.

matlab函数绘图三维(宏记软件四)(2)

2.条带图

Matlab中绘制条带图一般使用ribbon函数绘制。构建数据一般使用 peaks 函数, peaks 函数是通过平移和缩放高斯分布获得的公式,在绘制三维图中比较实用。绘制方法如下:

左边代码为:

[x,y] = meshgrid(-3:0.25:3,-3:0.2:3);

z = peaks(x,y);

ribbon(y,z)

代码的含义为x在-3到3的过程中每隔0.25取一点,y在-3到3的过程中每隔0.2取一点,然后用meshgrid 函数将 x 和 y 两个向量指定地域转换为矩阵 X 和 Y。再用peaks(x,y)函数对高度z进行赋值。最后通过ribbon函数输出。如下图:

2. Strip chart

The strip chart in Matlab is generally drawn using the ribbon function. The peaks function is generally used to construct the data. The peaks function is a formula obtained by translating and scaling the Gaussian distribution, which is more practical for drawing 3D graphs. The drawing method is as follows:

The code on the left is:

[x,y] = meshgrid(-3:0.25:3,-3:0.2:3);

z = peaks(x,y);

ribbon(y,z)

The meaning of the code is that x takes a point every 0.25 in the process of -3 to 3, and y takes a point every 0.2 in the process of -3 to 3, and then use the meshgrid function to convert the fields specified by the two vectors of x and y into Matrices X and Y. Then use the peaks(x,y) function to assign the height z. Finally, it is output through the ribbon function. As shown below:

matlab函数绘图三维(宏记软件四)(3)

3. 三维等高线图

在matlab中一般用contour3函数绘制三维等高线图。使用方法如下:

左边代码为:

[X,Y] = meshgrid(-5:0.5:5);

Z = X.^2 Y.^2;

contour3(Z)

代码含义为:代码的含义为x,y都在-5到5的过程中每隔0.5取一点,然后用meshgrid 函数将 x 和 y 两个向量指定的域转换为矩阵 X 和 Y。对高度Z进行赋值Z=X2 Y2。最后绘制等高线。在这个例子中,让软件随机选择 x 和 y 轴的等高线和范围。

3. 3D contour map

In matlab, the contour3 function is generally used to draw a three-dimensional contour map. The method of use is as follows:

The code on the left is:

[X,Y] = meshgrid(-5:0.5:5);

Z = X.^2 Y.^2;

contour3(Z)

The meaning of the code is: the meaning of the code is that x and y are taken every 0.5 points in the process of -5 to 5, and then the meshgrid function is used to convert the fields specified by the two vectors of x and y into matrices X and Y. Assign the value Z=X2 Y2 to the height Z. Finally draw the contour lines. In this example, let the software randomly choose the contours and ranges for the x and y axes.

matlab函数绘图三维(宏记软件四)(4)

4. gtext函数

在matlab中,gtext函数可以使用鼠标将文本添加到图窗,一般应用于二维的图窗中。使用方法如下:

左边代码为:

plot(3:45)

t = gtext('matlab learning')

代码含义为:使用plot函数绘制3:45的二维图窗,然后使用gtext函数将“matlab learning”贴在鼠标选取的位置。

4. gtext function

In matlab, the gtext function can use the mouse to add text to figures, generally used in two-dimensional figures. The method of use is as follows:

The code on the left is:

plot (3:45)

t = gtext('matlab learning')

The meaning of the code is: use the plot function to draw a 3:45 two-dimensional figure, and then use the gtext function to paste "matlab learning" at the position selected by the mouse.

matlab函数绘图三维(宏记软件四)(5)

今天的分享就到这里了。

如果您对今天的文章有独特的想法,

欢迎给我们留言,

让我们相约明天。

祝您今天过得开心快乐!

That's it for today's sharing.

If you have a unique idea about today’s article,

welcome to leave us a message,

let us meet tomorrow.

I wish you a happy day today!

参考资料:谷歌翻译

本文由LearningYard学苑整理发出,如有侵权请在后台留言!

LearningYard学苑

文字 | clear

排版| clear

审核| 任务达人

,

免责声明:本文仅代表文章作者的个人观点,与本站无关。其原创性、真实性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容文字的真实性、完整性和原创性本站不作任何保证或承诺,请读者仅作参考,并自行核实相关内容。文章投诉邮箱:anhduc.ph@yahoo.com

    分享
    投诉
    首页