This tutorial focused on the set() and get() functions for maximum comparability however, all of the same principals apply to using the newer interface. The set() and get() methods still work, however, it is often much more convenient to use the objects directly. It is important to note that MathWorks introduced the HG2 Graphics system starting in MATLAB R2014b which allows you to directly access graphic objects using the dot operator. Additional tutorials will cover more uses of these functions on figures, axes, and many other objects. The set() and get() functions are extremely useful in MATLAB and this tutorial barely scratched the surface of the many properties that should be regularly tweaked. The following code would match the size and location of figure f2 to that of figure f1. Imagine that had two figures open with handles f1 and f2. A simple example to create a figure that is 3 inches wide by 4 inches tall would look like this: set( f1, 'units', 'inches' ) set( f1, 'position', ) Īnother really nice thing to do is to combine both commands to let you programmatically set multiple figures to have the same properties or properties that are related in some way. It is also very helpful when you are trying to prepare plots for publications. This can be extremely useful if you are running the same code on multiple displays and need a consistent output. It is also often useful to specify a figure size in inches. This name will also show up at the top of the figure window now. set( f1, 'name', 'Figure Properties Tutorial' ) figureName = get( f1, 'name' ) disp( figureName ) Figure Properties Tutorial For example, we can change the figure name using a similar syntax. Now using the set() method we can change properties on the figure. figureName = get( f1, 'name' ) disp( figureName ) '' This property will be an empty string by default. For example, we can return the current figure name by using the keyword, ‘name’, with the get() function. Rather than returning all of the properties, we can also request a specific property that we are interested in. figureInfo = get( f1 ) disp( figureInfo ) scalar structure containing the fields: beingdeleted = off busyaction = queue buttondownfcn = (0x0) children = (0x1) clipping = on createfcn = (0x0) deletefcn = (0x0) handlevisibility = on hittest = on interruptible = on parent = 0 pickableparts = visible selected = off selectionhighlight = on tag = type = figure uicontextmenu = (0x0) userdata = (0x0) visible = on alphamap = closerequestfcn = closereq color = 1 1 1 colormap = currentaxes = (0x0) currentcharacter = currentobject = (0x0) currentpoint = 0 0 dockcontrols = off filename = graphicssmoothing = on integerhandle = on inverthardcopy = on keypressfcn = (0x0) keyreleasefcn = (0x0) menubar = figure name = number = 2 nextplot = add numbertitle = on outerposition = 1 552 562 529 paperorientation = portrait paperposition = 0.25000 2.50000 8.00000 6.00000 paperpositionmode = manual papersize = 8.5000 11.0000 papertype = usletter paperunits = inches pointer = arrow pointershapecdata = pointershapehotspot = 0 0 position = 300 200 560 420 renderer = opengl renderermode = auto resize = on resizefcn = (0x0) selectiontype = normal sizechangedfcn = (0x0) toolbar = auto units = pixels windowbuttondownfcn = (0x0) windowbuttonmotionfcn = (0x0) windowbuttonupfcn = (0x0) windowkeypressfcn = (0x0) windowkeyreleasefcn = (0x0) windowscrollwheelfcn = (0x0) windowstyle = normal Note, that in a few places long matrices in the output have been replaced with “” for illustration. The example below displays the figure properties. In MATLAB this will return an object, but in Octave, this will return a struct. Using the get() function we can examine the properties on the figure. In Octave and older versions of MATLAB (r2014a and older), this will return an index however, in recent versions of MATLAB this will return a graphics object. Let’s start out by creating a figure and saving its handle. The example outputs included in this tutorial were run using Octave. Specifically, we will be focusing on Figures however, these methods can be applied to many different objects.Īll of the example code is available in the Coding Tips GitHub repository and should run in both MATLAB and Octave. In this tutorial, we are going to walk through two basic functions, get() and set(), that can be used to manipulate the properties of graphic objects in MATLAB. Using set() and get() to update your graphics objects
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |