分享兴趣,传播快乐,增长见闻,留下美好。
亲爱的您。
这里是LearingYard学苑!
今天小编为大家带来Matlab二维绘图及label语法.
欢迎您的用心访问!
本期推文阅读时长大约5分钟,请您耐心阅读。
Share interest, spread happiness,
increase knowledge, and leave beautiful.
Dear you.
This is the LearingYard Academy!
Today, the editor brings Matlab two-dimensional drawing and label syntax.
Welcome your visit!
The reading time of this tweet is about 5 minutes, please read it with patience.
大家好,上期系列推文介绍了二维绘图中的线性图如何制作(plot函数),这期介绍其他类型的二维图如何制作以及所用的函数,另外介绍label函数的使用方法。
Hello everyone, the last series of tweets introduced how to make linear graphs in 2D drawing (plot function). This issue introduces how to make other types of 2D graphs and the functions used. In addition, it introduces how to use the label function.
一.条形图
在Matlab创建垂直条形图一般使用的是bar(英文是条纹,栏的意思) 函数,而创建水平条形图用的是barh 函数。操作如下:
左边代码为
y=[60 90 105 115 130 150 170 195 210 235 270] bar(y)
很好理解matlabfunction函数的用法,对y集合的各个元素赋值,然后用bar函数将y以竖向条形图的形式输出。当然也可以使用其他的数学函数,这里只用了简单的集合。
1. Bar Chart
The bar function is generally used to create vertical bar charts in Matlab, while the barh function is used to create horizontal bar charts. The operation is as follows:
The code on the left is
y=[60 90 105 115 130 150 170 195 210 235 270] bar(y)
is well understood, assigns values to each element of the y set, and then uses the bar function to output y in the form of a bar graph. Of course other mathematical functions can be used, but only simple sets are used here.
用barh函数将bar函数替换就能得到横向条形图:
Replacing the bar function with the barh function yields the following image:
二. 阶梯图
在Matlab创建阶梯图一般使用的是stairs(英文阶梯的含义)函数。使用方法如下
左边为代码为x = 0:0.5:20;
y = sin(2*x);
stairs(x,y)
含义是自变量x 在0-20范围,并且0.5间隔取一点,因变量为sin(2*x),使用stairs输出x,y。
2.Step diagram
Stairs (the meaning of English steps) function is generally used to create ladder diagrams in Matlab. The method of use is as follows
The code on the left is x = 0:0.5:20;
y = sin(2*x);
stairs(x,y)
The meaning is that the independent variable x is in the range of 0-20, and a point is taken at 0.5 intervals, the dependent variable is sin(2*x), and stairs is used to output x, y.
三. 散点图
在Matlab创建散点图一般使用的是scatter函数。使用方法如下:
左边为代码为x=linspace(0,4*pi,150)
y=sin(x)+rand(1,150)
scatter(x,y)
含义是x在0-4π中等距离取150个点,因变量y=sin(x)+(大小在0-1之前1列150行的矩阵里随机数),最后用scatter函数输出。
3.Scatter plot
The scatter function is generally used to create scatter plots in Matlab. The method of use is as follows:
The code on the left is x=linspace(0,4*pi,150)
y=sin(x)+rand(1,150)
scatter(x,y)
The meaning is that x takes 150 points at an intermediate distance of 0-4π, the dependent variable y=sin(x)+ (random number in the matrix with 1 column and 150 rows before 0-1), and finally uses the scatter function to output.
四. 极坐标图
在Matlab创建散点图一般使用的是polarplot函数,此函数可以在极坐标中绘制线条。极坐标图需要结合 theta 和rho 函数来使用。使用方法如下:
其中theta 是角度值,rho 是半径值,对这两个赋值之后,使用polarplot进行输出。
4.Polar plot
The polarplot function is generally used to create scatter plots in Matlab, which can draw lines in polar coordinates. Polar plots need to be used in conjunction with theta and rho functions. The method of use is as follows:
where theta is the angle value and rho is the radius value. After assigning these two values, use polarplot to output.
五. label函数
label函数有多种使用方法,比较常用的有xlabel、ylabel、labeledge、labelText等等。下面介绍在这四种函数.
xlabel函数指在x轴上添加标签matlabfunction函数的用法,ylabel函数指在y轴上添加标签,用上面已经画过的图举例:
5.label function
There are many ways to use the label function, the more commonly used ones are xlabel, ylabel, labeledge, labelText and so on. These four functions are described below.
The xlabel function refers to adding a label to the x-axis, and the ylabel function refers to adding a label to the y-axis. Take the figure already drawn as an example:
labeledge函数指为图边添加标签,labelText打上文本标签。我们通过一个无向边图说明如何使用这两个函数。
先画一个无向图:
The labeledge function refers to adding labels to the image edges, and labelText labels the text. We illustrate how to use these two functions through an undirected edge graph.
First draw an undirected graph:
labeledge 可以添加权重标签,labelText可以添加文本标签
labeledge使用 :
weights = [5 10 15 20 25];
labeledge(h,1:numedges(N),weights)
先设置权重,再添加进去。
labeledge can add edge weight labels, labelText can add text labels
labeledge uses:
weights = [5 10 15 20 25];
labeledge(h,1:numedges(N),weights)
set the weight first, then add it.
labelText使用:
labelText = {'A'};
labeledge(h,[1],labelText)
先写文本 再将文本内容标在第一条边上。
labelText uses:
labelText = {'A'};
labeledge(h,[1],labelText)
Write the text first When speaking, the text content is marked on the first edge.
———END———
限 时 特 惠:本站每日持续更新海量各大内部创业教程,一年会员只需128元,全站资源免费下载点击查看详情
站 长 微 信:jiumai99