《科学计算科学计算 (45).pdf》由会员分享,可在线阅读,更多相关《科学计算科学计算 (45).pdf(19页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、ChapterChapter 8 8 MATLABMATLAB GraphicalGraphical UserUserInterfaceInterface DesignDesign8.1 Figure and Axes8.2 Line and Surface8.3 Ways to Develop Apps8.4 App Development Using GUIDE8.5 App Development Using App Designer8.6 Examples of App DevelopmentHandleHandle ofof a a GraphicsGraphics ObjectOb
2、jectGraphicsGraphics ObjectObject PropertiesPropertiesF Figureigure ManipulationManipulationAxesAxes ManipulationManipulation8.1 Figure and Axes8.1 Figure and Axes1.Handle of a Graphics Object1.Handle of a Graphics Object(1)Whats a handle?A graph in MATLAB is composed of several specific graphics ob
3、jects.A handle is used to identify an object,and to access the properties of the object.Example 1:Create several plots and save their handles.t=0:pi/10:2*pi;h1=plot3(t+pi,t-2*pi,sin(t),r);hold on;x,y=meshgrid(t);z=sin(x);h2=mesh(t-2*pi,t+pi,z);x3,y3,z3=cylinder(t);h3=surf(x3,y3,z3);1.Handle of a Gra
4、phics Object1.Handle of a Graphics Object(2)Access graphics objectsAccessing graphics objects refers to getting or setting the properties of graphics objects.Different graphics objects have different properties,but methods accessed are the same.Object.PropertyName x=0:pi/10:2*pi;y=sin(x);h0=plot(x,y
5、);h0.Colorans=0 0.4470 0.7410 h0.LineWidth=2;h0.LineStyle=-.;1.Handle of a Graphics Object1.Handle of a Graphics Object(3)Get handles of specific graphics objectsgcf:get the handle of the current figure window.gca:get the handle of the current axes.gco:get the handle of the last object selected.find
6、obj:locate graphics objects based on the value ofthe specific property.1.Handle of a Graphics Object1.Handle of a Graphics Object2.Graphics 2.Graphics Object PropertiesObject Properties(1)Common properties of graphics objectsChildren:An array composed of the handles of all child objects.Parent:Handl
7、e of the parent container.Type:Type of an object.It is read-only.Tag:Identifier of an object.subplot(1,2,1)h1=fplot(t)t.*sin(t),(t)t.*cos(t),0,6*pi);axis equalsubplot(1,2,2)x,y,z=peaks(20);h2=mesh(x,y,z);h10=h1.Parent;h10.Color=y;h1.Color=r;h2.Parent.Color=cyan;2.Graphics 2.Graphics Object Propertie
8、sObject PropertiesExample 2:Create a line and a surface in two subplots respectively.Set the background colorof subplot 1 to yellow and the line color to red.Set the background color of subplot 2 to cyan.2.Graphics 2.Graphics Object PropertiesObject Properties(2)Dynamic properties of graphics object
9、sKeyPressFcn:in response to a keypress event.CreateFcn:responds when a graphics object is created.DeleteFcn:responds when a graphics object is deleted.WindowButtonDownFcn:in response to a click event.ButtonDownFcn:in response to a click event3 3.Figure Manipulation.Figure Manipulation(1)Create figur
10、e objectMATLAB creates figure objects through the figure function.Syntax:handle=figure(property1,value1,property2,value 2,)Properties are used to set the appearance of a figure window.handle=figureCreate the figure window using default property values.figure(handle)Make the figure corresponding to t
11、his handle the current window.3 3.Figure Manipulation.Figure Manipulation(2)Properties of figureMenuBar:Display or hide the default menus.The value is none or figureName:The name of a figure.NumberTitle:Whether the title of the figure includes the phrase Figure n.Color:Background color of a figure.3
12、 3.Figure Manipulation.Figure Manipulation(2)Properties of figurePosition:Location and size of the drawable area.Its value is a row vector withfour elements,x,y,w,h.Units:Units of measurement,which affects the Size and Position property.pixels:Specify the measurement unit as pixels.(default)inches:S
13、pecify the measurement unit as inches.centimeters:Specify the measurement unit as centimeters.points:Specify the measurement unit as points.normalized:Specify units as the proportion to this area.hf=figure;hf.Color=0,1,1;hf.Position=1,1,300,150;hf.Name=Example of Figure;hf.NumberTitle=off;hf.MenuBar
14、=none;hf.ButtonDownFcn=gtext(Hello,World!);Example 3:Create a figure window.The figure window has no menu bar and its title is Example of Figure.It locates at the left-bottom corner of the desktop,with a width of 300 pixelsand a height of 150 pixels.And the background is cyan.When the user press any
15、 key and clickin the figure,Hello,World will be displayed at the location of the mouse pointer.3 3.Figure Manipulation.Figure Manipulation4.Axes 4.Axes ManipulationManipulation(1)Create axes objectMATLAB creates axes objects through the axes function.Syntax:handle=axes(property1,value1,property2,val
16、ue 2,)Properties are used to set the appearance of the axes.handle=axesCreate the axes using default property values.axes(handle)Set the current axes.4.Axes 4.Axes ManipulationManipulation(2)Properties of axesPosition:Location and size of the axes in the figure.Units:Units of measurement.Its default
17、 value is normalized.Box:Whether display the box outline around the axes.It can be specified as on or off(Default).GridLineStyle:Line style for grid lines.It can be specified as:(Default),-,-.,-,or none.Title:Axes title.Its value is the handle of the object created by the title function.4.Axes 4.Axe
18、s ManipulationManipulation(2)Properties of axesXlabel,Ylabel,Zlabel:Handles of axis label objects created by the xlabel,ylabel,and zlabelfunctions.XLim,YLim,Zlim:The lower limit and upper limit of x-,y-,z-axis.Their value is two-element vectors Lmin,Lmax.The default value is 0,1.XScale,YScale,Zscale
19、:Scale of values along x-,y-,z-axis,specified as linear scale or logscale.The default value is linear.View:The azimuth and elevation of view,specified as a two-element vector az,el.The azspecifys the azimuth of view and the el specifys the elevation.The default value is 0 90.ha1=axes(Position,0.1,0.
20、1,0.7,0.7);contour(peaks(20)ha1.Title=title(等高线等高线);ha1.YLabel=ylabel(南北向南北向);ha1.XLabel=xlabel(东西向东西向);ha2=axes(Position,0.65,0.7,0.28,0.28);surf(peaks(20)ha2.View=-30,45;Example 4:Split the figure window using axes objects.4.Axes 4.Axes ManipulationManipulation(2)Properties of axesColorOrder-The p
21、alette of colors MATLAB uses to create plot objects.It is a three-columnmatrix of RGB triplets.Each RGB triples represents one color.The default array has 7 rows.hc=gca;C=hc.ColorOrderC=0 0.4470 0.74100.8500 0.3250 0.09800.9290 0.6940 0.12500.4940 0.1840 0.55600.4660 0.6740 0.18800.3010 0.7450 0.933
22、00.6350 0.0780 0.18404.Axes 4.Axes ManipulationManipulationx=0,0;y=0,1;ha=axes;ha.ColorOrder=0,0,0;1,0,0;0,1,0;0,0,1;hold onplot(x,y,x+0.5,y,x+1,y,x+1.5,y,x+2,y,x+2.5,y);ha.XLim=-0.2,3;ha.YLim=-0.2,1.2;4.Axes 4.Axes ManipulationManipulationExample 5:Set the ColorOrder property for the figure containing 4 colors.Then plot 6 curves.