当前位置:网站首页>Graphic drawing in MATLAB
Graphic drawing in MATLAB
2022-04-21 17:50:00 【User 9688532】
MATLAB Graphics are usually drawn by tracing points 、 The way of connection . The graphic drawing is realized by providing the point coordinates of key positions and the specific link between points .
At the same time, it supports drawing multiple graphics on the same picture , In order to distinguish different graphics , Available in different colors 、 size 、 Shape and link mode to distinguish different graphics .
Drawing of two-dimensional graphics
because MATLAB The figure is drawn by tracing points 、 Connected to achieve , Therefore, when drawing simple plane graphics, it is necessary to provide the horizontal and vertical coordinates of a series of points on the graphics , Then link these points . The specific graphic drawing command is :
plot(X,Y,’S’)
among X,Y It's a vector , They are vectors composed of abscissa and ordinate of all points ,S It's a string , Used to determine the color of the line , The drawing shape of points and the link mode between points .
matlab Implicit function drawing by entering... In the command window help plot Commands can be viewed S Specific writing method of .Y Sometimes it can be a matrix , At that time, multiple curves will be drawn for the same independent variable .
example
With vectors y=(1,2,5,4.5,3,6,1) The components of are ordinates , The component serial number is the abscissa drawing sequence connecting line .
Explain : Enter the command
y=1 2 5 4.5 3 6 1;
plot(y)
example
Draw a sine curve and a cosine curve .
>>x=0:pi/10:2*pi; % Construct vectors
>>y1=sin(x); % The structure corresponds to y1 coordinate
>>y2=cos(x); % The structure corresponds to y2 coordinate
>>plot(x,y1,x,y2) % Draw a picture to x Abscissa ,y1,y2 Figure with vertical coordinates
Be careful
① The so-called colon method is used to construct the vector , The format is
Vector name = initial value : step : Final value % In steps of 1 You can omit .
②plot Is to draw a curve for the column of a vector or matrix , in other words , Use plot You must first define the of each point on the curve x Coordinates and y coordinate .
③ In the above format ,x and y Can be expressions .
④ If the interval between independent variables is large , The smooth curve will show the original appearance of the polyline .
example
matlab Beginner's course students with excellent grades in a certain exam account for 8%, Good accounting for 20%, Medium accounts for 36%, Those who pass account for 24%, Those who fail account for 12%. It is represented by pie chart and bar chart respectively .
Explain :
x=8 20 36 24 12;
subplot(221);pie(x,1 0 0 0 1);
title(' The pie chart ');
subplot(222);bar(x,'grpup');
title(' Vertical bar chart ');
subplot(223);bar(x,'stack');
title(' Vertical bar chart whose cumulative value is ordinate ');
subplot(224);barh(x,'group');
title(' Horizontal Bar Graph ');
About curve control commands
In the use of plot You can specify the color of the curve when drawing the curve with the command 、 Linetype and data point icons . The basic call format is
plot(x,y,'color line-style marker')
Be careful
① Color 、 Linetype 、 The symbols marking the three attributes must be placed in the same string .
② The order of attributes doesn't matter , You can specify only one or two properties , You can also default to all , But the same attribute cannot specify two at the same time .
③ The default color is blue .
④ spot 、 The line identifier defaults to solid line .
⑤ There is no interval between attributes .
example
In red 、 Point connection 、 Cross to draw a sine curve .
>>x=0:0.2:8;
>>y=sin(x);
>>plot(x,y,'r:x')
About drawing annotation commands
example
Add grids and labels to the graphics of the above example .
>>x=0:pi/10:2*pi;
>>y1=sin(x);
>>y2=cos(x);
>>plot(x,y1,x,y2)
>>grid on % Adding grid
>>xlabel(‘x Axis ’) % Cross sitting label
>>ylabel(‘y Axis ’) % Ordinate name
>>title(‘ Sine and cosine function curves ’) % title
>>text(1.5,0.3,’cos(x)’) % Specify the location dimension
>>gtext(‘sin(x)’) % Use the mouse to select the position label
>>axis(0 2*pi -1.2 1.2 % Set the maximum and minimum value of the coordinate axis
hold on(/off) Keep drawing commands
subplot(n,m,k) Divide the graphics window into n That's ok m Make a grid , In the k A grid drawing , The grid is counted in rows from top to bottom .
example
In the same window , Use twice plot function , Draw two curves .
>>x=0:0.2:12;
>>plot(x,sin(x),’-’)
>>hold on
>>plot(x,cos(x),’:’)
example
Divide the current window into four areas , Draw four function curves .
>>x=0:0.05:8;
>>y1=2*sin(x);
>>y2=2*cos(x);
>>y3=sin(2*x);
>>y4=cos(2*x);
>>subplot(2,2,1);
>>plot(x,y1);
>>title(‘2sinx’)
>>subplot(2,2,2);
>>plot(x,y2);
>>title(‘2cosx’)
>>subplot(2,2,3);
>>plot(x,y3);
>>title(‘sin2x’)
>>subplot(2,2,4);
>>plot(x,y4);
>>title(‘cos2x’)
Drawing of three-dimensional graphics
stay MATLAB The command for drawing 3D curves in is
plot3(x,y,z,’S’)
among x,y,z They are the horizontal of points 、 Vertical and vertical coordinates ,S For the string ,matlab Four dimensional graph Similar to the drawing string of two-dimensional graphics .
stay MATLAB Draw three-dimensional arrow function in
quiver3(x,y,z,u,v,w)
example
Trial drawing
The graphic .
Explain
Enter the following commands in the command window , The figure shown in the figure can be obtained .
t=0:0.01:10*pi;
x=sin(t);
y=cos(t);
plot3(x,y,t,'g');
The commands for drawing 3D surfaces are mesh(x,y,z) or surf(x,y,z). The difference is , The former draws a surface approximated by a mesh , The latter draws a true surface .
example
Draw a multimodal function diagram .
>>z=peaks(40);
>>mesh(z);
>>surf(z);
peaks It is called multimodal function , Commonly used for the demonstration of 3D surfaces .
example
Trial drawing z=x²-y² The graphic .
Explain
First, take the horizontal and vertical coordinates , Enter the following command
x=-10:0.5:10;
y=-10:0.5:10;
Second, use meshgrid Command to generate horizontal and vertical cross grid coordinates , The specific command is as follows :
xx,yy=meshgrid(x,y)
Finally, generate vertical coordinates and draw . The specific command is as follows :
z=xx.^2-yy.^2;
mesh(xx,yy,z);
Decoration of graphics
(1) Coordinate axis and drawing name
The following commands can be used to name the coordinate axis and graphics
xlabel(‘ Specific name ’)
ylabel(‘ Specific name ’)
zlabel(‘ Specific name ’)
title (‘ Specific name ’)
(2) Add grid
adopt grid on or grid off Command to add grid or delete grid .
(3) Add embellishment to the graph
In order to add text to the graphics to realize the decoration of the graphics , It can be done by gtext(‘string’) To achieve the decoration of graphics . When running gtext On command , A cross will appear on the screen , Move the cross to the specified position and press the left key , The marked string will be placed in this position .
版权声明
本文为[User 9688532]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204211744362907.html
边栏推荐
- C# ODBC将一个文件夹的文件装载到MySQL数据库BLOB列,并将BLOB列下载到另一个文件夹
- 每周推荐短视频:企业之间的竞争是看谁能抢占先机
- 本田北美产品规划发布!Insight混动停产,CR-V、雅阁即将发布
- 漏洞检测与防御:Redis未授权访问漏洞复现
- Considering loose coupling of microservice architecture? Be careful of these traps
- Brief introduction of common methods of wireless DoS attack
- 【AI与食品】北工商中科院计算所最新《基于视觉分析的膳食评估》综述性论文
- Detailed explanation of spark SQL underlying execution process
- How to get the map value is not so low. There are three ways to get the map parameters
- 综述:CFD的未来之路
猜你喜欢

Analysis on the adaptation layer of openharmony UI framework (I)
MySQL ODBC驱动简介

STM32学习笔记——RTC的亚秒值校准

单片机能做什么,你有什么有单片机或开源硬件做的有意思的作品吗

上位机这样玩,才有意思!

华为URPF

将模型训练外包真的安全吗?新研究:外包商可能植入后门,控制银行放款

Zhongang Mining: a new and active application field of fluorite resources

俄乌冲突引发顾虑 五眼网络安全部门建议盟友增强关键基础设施防护

Beijing quasi GPS Beidou satellite timing system helps South Asia electronic production management system
随机推荐
Zhongang Mining: a new and active application field of fluorite resources
Deep cultivation of the industry for decades, interpretation from multiple perspectives! Digital IT operation from the perspective of thinking transformation
看看技术宅怎么拯救学霸机,我用10块钱修好了笔记本电脑
Addition, deletion, modification and query of MySQL advanced table
Google has been unable to collect the transformation target on the mobile terminal. What's the matter?
Mysql database common sense storage engine
Modify the van dropdown menu default height
MOS管和IGBT有什么区别?别傻傻分不清了
WPF 引用 UWP 控件 不打包为 MSIX 分发的方法
The application of new technologies has opened the second path of industrial Internet
用户发送请求到执行controller方法的过程发生了什么
洞见科技首批通过央行国家金融科技测评中心「联邦学习」产品评测,实现「MPC+FL」金融应用双认证
ASE35P03-ASEMI场效应管35P03
LogStash~LogStash的工作原理
5000 movie datasets from tmdb
启牛理财课有用嘛?安全靠谱嘛?
短视频平台搭建,仿制一个登陆界面的demo
MP40N120-ASEMI场效应管MP40N120
MySQL basic collection
In cabin visual AI application front loading "increased by nearly 200% year-on-year". Which suppliers lead the Chinese market