matlab二维图入门(周二软件打卡一)

matlab二维图入门(周二软件打卡一)(1)

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

亲爱的您,

这里是LearingYard学苑!

今天小编为大家带来Matlab二维绘图介绍,

欢迎您的用心访问!

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

Share interests, spread happiness, increase knowledge, and leave behind beauty.

Dear you,

this is LearningYard Academy!

Today, the editor brings you introduction of Matlab two-dimensional drawing,

welcome your visit carefully!

This tweet will take about 5 minutes to read . Please read it patiently.

#1

Plot语法

在Matlab帮助文档中可搜索到plot绘制二维线图时的函数语法如下:

The function syntax for plotting a two-dimensional line graph can be searched in the Matlab help documentation as follows:

plot(X,Y)

plot(X,Y,LineSpec)

plot(X1,Y1,...,Xn,Yn)

plot(X1,Y1,LineSpec1,...,Xn,Yn,LineSpecn)

plot(Y)

plot(Y,LineSpec)

plot(___,Name,Value)

plot(ax,___)

p = plot(___)

#2

实例操作

1、创建图像

创建x,它是100 个介于 −2π 和 2π 之间的线性间隔值。将 y1 和 y2 创建为 x 的正弦和余弦值。在编辑器窗口输入以下代码:

Create x, which is 100 linearly spaced values between −2π and 2π. Create y1 and y2 as the sine and cosine of x. Enter the following code in the editor window:

matlab二维图入门(周二软件打卡一)(2)

运行结果如下:

The results are as follows:

matlab二维图入门(周二软件打卡一)(3)

2、添加坐标轴标签

xlabel、ylabel函数用于给x、y轴贴上标签。该函数的用法如下:xlabel(‘string’):表示给当前轴对象中的x轴贴标签ylabel(‘string’):表示给当前轴对象中的y轴贴标签。利用 xlabel、ylabel、title 对函数图像进行标注。

在编辑器窗口继续输入以下代码:

The xlabel, ylabel functions are used to label the x and y axes. The usage of this function is as follows.xlabel('string'): Indicates labeling the x-axis in the current axis object.ylabel('string'): Indicates labeling the y-axis in the current axis object.Label the function image with xlabel, ylabel, and title.

Continue to enter the following code in the editor window:

matlab二维图入门(周二软件打卡一)(4)

运行结果如下:

The results are as follows:

matlab二维图入门(周二软件打卡一)(5)

3、添加图例

Legend函数用于在图形上添加图例。该命令对有多种图形对象类型(线条图、条形图、饼形图等)的窗口显示一个图例。对于每一线条,图例会在用户给定的文字标签旁显示线条的线型、标记符号和颜色等。该函数的用法如下:Legend(‘string1’, ‘ string2’,…, pos):表示用指定的文字string,在当前坐标轴中对所给数据的每一部分显示一个图例,在指定的位置放置这些图例。

输入以下代码:

The Legend function is used to add a legend to the graph. This command displays a legend for windows with several types of graphic objects (line, bar, pie, etc.). For each line, the legend displays the line style, marker symbol, color, etc. of the line next to the text label given by the user. The usage of this function is as follows:Legend

('string1', 'string2',..., pos): Indicates that with the specified text string, a legend is displayed for each part of the given data in the current coordnate axis, and these legends are placed at the specified position.

Enter the following code:

matlab二维图入门(周二软件打卡一)(6)

运行结果如下:

The results are as follows:

matlab二维图入门(周二软件打卡一)(7)

4、添加文本到图窗

gtext函数用于在当前二维图形中用鼠标放置文字。当光标进入图形窗口时,会变成一个大十字,表明系统正等待用户的动作。该函数的用法如下:gtext(‘string’):表示当光标位于一个图形窗口内时,等待用户单击鼠标或键盘。若按下鼠标或键盘,则在光标的位置放置给定的文字。使用函数gtext可以将一个字符串放到图形中,位置由鼠标来确定。

输入代码:

The gtext function is used to place text with the mouse in the current two-dimensional graphics. When the cursor enters the graphics window, it becomes a large cross, indicating that the system is waiting for user action. The usage of this function is as follows.gtext('string'): Indicates that when the cursor is in a graphics window, wait for the user to click the mouse or keyboard. Places the given text at the cursor's position if the mouse or keyboard is pressed.Use the function gtext to place a string in the graphic, the position is determined by the mouse.

Enter code:

matlab二维图入门(周二软件打卡一)(8)

运行结果如下:

The results are as follows:

matlab二维图入门(周二软件打卡一)(9)

5、绘制sinx、cosx图像,并改变图像线条外观、添加坐标轴标签、添加标题、添加文本到图窗

输入以下代码:

Draw sinx, cosx images, and change the appearance of image lines, add axis labels, add titles, and add text to figures

Enter the following code:

matlab二维图入门(周二软件打卡一)(10)

运行结果如下:

The results are as follows:

matlab二维图入门(周二软件打卡一)(11)

今天的分享就到这里了。

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

欢迎给我们留言,

让我们相约明天。

祝您今天过得开心快乐!

That's all for today's sharing.

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

please leave us a message,

and let us meet tomorrow.

I wish you a happy day !

,

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

    分享
    投诉
    首页