天天看点

文学文享(8):Matlab绘图学习之二维三维图绘制及相关基础操作

作者:LearningYard学苑
文学文享(8):Matlab绘图学习之二维三维图绘制及相关基础操作

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

亲爱的您,这里是LearningYard学苑!

今天小编为大家带来Matlab绘图学习分享。

欢迎您的访问!

Share interest, spread happiness, increase knowledge, and leave beautiful.

Dear, this is the LearingYard Academy!

Today, the editor brings the Matlab drawing learning and sharing.

Welcome to visit!

1 内容摘要(Content summary)

本文将分享小编学习Matlab绘图的过程,本次学习的是Matlab基础操作及二维图和三维图的基本绘制方法。

This article will share the editor's process of learning Matlab drawing. This time I will learn the basic operations of Matlab and the basic drawing methods of two-dimensional and three-dimensional graphics.

2 思维导图(Mind mapping)

文学文享(8):Matlab绘图学习之二维三维图绘制及相关基础操作

3 正文(Text)

3.1 Matlab入门学习(Matlab entry learning)

小编首先跟着教学,对Matlab的一些基础入门操作进行了学习,为之后学习Matlab绘图做了前期准备。在此期间学到了一些实用的功能和操作,将在下方进行展示。

The editor first followed the teaching and learned some basic introductory operations of Matlab, making preliminary preparations for learning Matlab drawing later. During this period, some useful functions and operations have been learned, which will be displayed below.

(1) Matlab可以进行矩阵的运算,分别给x和y赋值一个矩阵,利用运算符号便可进行计算。

(1) Matlab can perform matrix operations, assign a matrix to x and y respectively, and use operation symbols to perform calculations.

文学文享(8):Matlab绘图学习之二维三维图绘制及相关基础操作

在此学到的知识是:中括号中用分号隔开数字便可表示矩阵;每条命令后输入分号可将命令的输出结果不显示在命令行窗口内;在进行矩阵乘法时,前面的变量后加个“.”便可进行矩阵内相对位置数字的乘法而不是传统数学中的矩阵乘法。

The knowledge learned here is: The matrix can be represented by separating the numbers with a semicolon in the brackets. Entering a semicolon after each command can prevent the output of the command from being displayed in the command line window. When performing matrix multiplication, add a "." after the previous variable to perform multiplication of relative position numbers in the matrix instead of matrix multiplication in traditional mathematics.

(2) 可点击Matlab主页菜单栏中的新建脚本选项来构建脚本,脚本可以将多条代码封装起来,点击运行后得出最终结果。

(2) You can click the New Script option in the menu bar of the Matlab home page to build a script. The script can encapsulate multiple codes, and the final result can be obtained after clicking Run.

文学文享(8):Matlab绘图学习之二维三维图绘制及相关基础操作

在此学到的知识是:input()函数让用户输入一个数赋值给变量,提高了脚本交互性;fprintf()函数可输出一串字符,使结果更美观;\n表示换行;%f表示可带小数的浮点数,%g表示实数。

The knowledge learned here is: The input() function allows the user to input a number and assign it to a variable, which improves the script interactivity. The fprintf() function can output a string of characters to make the result more beautiful. \n means newline. %f means a floating-point number that can take a decimal. %g means a real number.

(3) 使用if函数可进行判断,从而跳过一些代码的执行。

(3) The if function can be used to judge, thereby skipping the execution of some codes.

文学文享(8):Matlab绘图学习之二维三维图绘制及相关基础操作

在此学到的知识是:elseif是if语句的延伸,用于处理两个以上结果的判断;判断一个数字是否等于0,要使用两个等于号;sqrt()表示根号;或者用“||”表示。

The knowledge learned here is: Elseif is an extension of the if statement, which is used to handle the judgment of more than two results. To judge whether a number is equal to 0, use two equal signs. sqrt() means the root sign. Or use "||" to indicate.

(4) while函数表示循环,在条件成立的情况下循环执行一定的代码。

(4) The while function represents a loop, and executes a certain code in a loop when the condition is true.

文学文享(8):Matlab绘图学习之二维三维图绘制及相关基础操作

在此学到的知识是:若开头不给变量重新赋值,那么重复运行数字会越加越大;disp()同样为输出语句,可输出带换行的值;不等于用“~=”表示;mod()用于取两数相除的商。

The knowledge learned here is: If the variable is not reassigned at the beginning, then the number will become larger and larger after repeated operations. disp() is also an output statement, which can output values with newlines. Not equal to use "~=" to express. mod() is used to take the quotient of dividing two numbers.

(5) for函数也用于表示循环。

(5) The for function is also used to represent loops.

文学文享(8):Matlab绘图学习之二维三维图绘制及相关基础操作

在此学到的知识是:在“i=2:1:8”中,冒号的作用是使初始为2的i,每次加1,最终加到8,两个冒号中间的值称为步长。

The knowledge learned here is: In "i=2:1:8", the role of the colon is to make i, which is initially 2, increase by 1 each time, and finally add to 8. The value between the two colons is called the step size.

(6) function是Matlab内的自建函数,可以创建具有某种特定功能的函数,然后在其他函数中方便地调用。下面是自建函数及套用的过程,最终输出1-1000内所有质数。

(6) Function is a self-built function in Matlab, you can create a function with a specific function, and then call it conveniently in other functions. The following is the self-built function and the process of applying it, and finally output all prime numbers within 1-1000.

文学文享(8):Matlab绘图学习之二维三维图绘制及相关基础操作
文学文享(8):Matlab绘图学习之二维三维图绘制及相关基础操作
文学文享(8):Matlab绘图学习之二维三维图绘制及相关基础操作

在此学到的知识是:使用%可以方便地为函数的每个步骤进行标记,以免忘了是什么意思。

The lesson learned here is that using % is a convenient way to label each step of a function so you don't forget what it means.

3.2 Matlab绘图学习(Matlab drawing learning)

(1) plot()函数是用于绘制线图的函数,最简单的形式为plot(x,y),会将(x,y)看作坐标点绘制到图上。

(1) The plot() function is a function used to draw a line graph. The simplest form is plot(x,y), which will treat (x,y) as a coordinate point and draw it on the graph.

文学文享(8):Matlab绘图学习之二维三维图绘制及相关基础操作

绘图时将x的步长设为一个较小的数,可使图像更加平滑。

Setting the x step size to a small number when plotting can make the image smoother.

文学文享(8):Matlab绘图学习之二维三维图绘制及相关基础操作
文学文享(8):Matlab绘图学习之二维三维图绘制及相关基础操作

plot()函数中用单引号标记部分表示图像的格式,-表示实线,o表示关键点用o标记,green表示绿色,颜色也可用单个字母表示,如k表示黑色。hold on的加入使得一张图中可绘制多条曲线,axis equal可使x和y轴的单位长度相同。

The part marked with single quotes in the plot() function indicates the format of the image, - indicates a solid line, o indicates that key points are marked with o, green indicates green, and the color can also be expressed by a single letter, such as k indicates black. The addition of hold on allows multiple curves to be drawn in one graph, and axis equal makes the unit lengths of the x and y axes the same.

文学文享(8):Matlab绘图学习之二维三维图绘制及相关基础操作

plot3()函数表示绘制三维图像,在确定了二维图像关键点数量后,需在z轴确定相同数量的关键点。

The plot3() function means to draw a three-dimensional image. After determining the number of key points of the two-dimensional image, it is necessary to determine the same number of key points on the z-axis.

文学文享(8):Matlab绘图学习之二维三维图绘制及相关基础操作

为图像添加标题使用title()函数,为坐标轴添加标签分别使用xlabel()和ylabel()。

Add a title to the image using the title() function, and add labels to the axes using xlabel() and ylabel() respectively.

文学文享(8):Matlab绘图学习之二维三维图绘制及相关基础操作

使用subplot()函数可将多幅图画在同一个窗口内的不同位置,函数内的三个数字分别代表将窗口分成几行几列及将图片画在哪个位置。

Use the subplot() function to draw multiple pictures at different positions in the same window. The three numbers in the function represent how many rows and columns the window will be divided into and where the pictures will be drawn.

文学文享(8):Matlab绘图学习之二维三维图绘制及相关基础操作

(2) surf()函数用于画三维图像中的一个面,利用meshgrid()函数找到平面内所有点后,即可绘制出一个曲面图像。

(2) The surf() function is used to draw a surface in a three-dimensional image. After finding all the points in the plane using the meshgrid() function, a surface image can be drawn.

文学文享(8):Matlab绘图学习之二维三维图绘制及相关基础操作

今天的分享就到这里了。

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

欢迎给我们留言,

让我们相约明天。

祝您今天过得开心快乐!

That's all for today's sharing.

If you have a unique idea about the article,

please leave us a message,

and let us meet tomorrow.

I wish you a nice day!

参考资料:

翻译:

Google翻译

文字:

https://space.bilibili.com/24014925/channel/seriesdetail?sid=1446602

图片:

自制

版权说明:

本文由LearningYard学苑整理并发出,如有侵权请后台留言沟通。

文案I姜疯雨火

排版I姜疯雨火

审核IGoldfish

继续阅读