More Matlab Graphics and GUI Graphics subplots some
More Matlab Graphics and GUI Graphics subplots some useful commands 3 D graphics GUI controls The callback property Other essential properties
Comments about the “Game of Life” Initial universe Time step
Time step input universe embed Count neighbors Make decisions output universe
Count neighbors input universe Count the neighbors of a cell Matrix with the neighbors numbers
Subplots Subplot II
h 1 = subplot(7, 7, [1 8 15 22 29 36 2 9 16 23 30 37 3 10 17 24 31 38 4 11 18 25 32 19 5 12 19 26 33 40 6. . . 13. . . 20. . . 27. . . 34. . . 41]); 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
h 1 = subplot(7, 7, [1 8 15 22 29 36 get(h 1, 'type') ans = axes 2 9 16 23 30 37 3 10 17 24 31 38 4 11 18 25 32 19 5 12 19 26 33 40 6. . . 13. . . 20. . . 27. . . 34. . . 41]);
h 2=axes
subplot(7, 7, [7 14])
subplot(7, 7, [7 14])
h 1 = subplot(7, 7, [1 8 15 22 29 36 subplot(7, 7, [7 14]) 2 9 16 23 30 37 3 10 17 24 31 38 4 11 18 25 32 19 5 12 19 26 33 40 6. . . 13. . . 20. . . 27. . . 34. . . 41]); 1 8 2 9 3 10 4 11 5 12 6 13 7 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
Useful Commands The interactively edited figure/axes/object is accessible through the gcf/gca/gco commands (get current figure/axes/object). >> get(gca) ALim = [0 1] ALim. Mode = auto Ambient. Light. Color = [1 1 1] Box = on Camera. Position = [5. 5 17. 3205] Camera. Position. Mode = auto Camera. Target = [5. 5 0] Camera. Target. Mode = auto Camera. Up. Vector = [0 1 0] Camera. Up. Vector. Mode = auto
plot(x, y)
hl=findobj(gcf, ’type’, ’line’)
hl=findobj(gcf, ’type’, ’line’) set(h 1, 'color', 'r');
set(gcf, 'tag', 'first‘); Figure; y = x. ^-2; plot(x, y);
first. Figure = findobj('tag', 'first'); h 2 = findobj(first. Figure, 'type', 'line') set(h 2, 'marker', '*');
first. Figure = findobj('tag', 'first'); h 2 = findobj(first. Figure, 'type', 'line') set(h 2, 'marker', '*');
3 D graphics x = [-2: 0. 2: 2] x = [ -2 -1. 8 …. 1. 8 2] y = [-4: 0. 4: 4] y = [ -4 -3. 6 …. 3. 6 4] We want to calculate and display Z=x(x 2 -y 2)
3 D graphics surf(XX, YY, ZZ) size(XX) ans = 21 21 XX(1: 5, 1: 5) ans = -2. 0000 -1. 8000 -1. 6000. . replica of x -1. 4000 -1. 2000 …. length(y) -1. 2000 …. rows -1. 2000 ….
surf(XX, YY, ZZ) size(XX) ans = 21 21 XX(1: 5, 1: 5) ans = -2. 0000 -1. 8000. . -1. 6000 -1. 4000 -1. 2000 ….
surf(XX, YY, ZZ) size(XX) ans = 21 21 XX(1: 5, 1: 5) ans = -2. 0000 -1. 8000. . -1. 6000 -1. 4000 -1. 2000 ….
3 D graphics surf(XX, YY, ZZ) size(YY) ans = 21 21 YY(1: 5, 1: 5) ans = -4. 0000 -3. 6000 -3. 2000 -2. 8000 -2. 4000. Length(x) columns. replica of y -4. 0000 -3. 6000 -3. 2000 -2. 8000 -2. 4000 …. …. ….
3 D graphics surf(XX, YY, ZZ) size(ZZ) ans = 21 21 ZZ = XX. *(XX. ^2 -YY. ^2); Element-by-element matrix operations
How do we create XX and YY? [XX YY] = meshgrid(x, y); Were [XX YY] = meshgrid(x) is the same as [XX YY] = meshgrid(x, x);
How does Matlab know how to relate some value with a specific color? Colormaps! A colormap is an m-rows by 3 column matrix Each row is a color specified in RGB values (between 0 and 1) C=get(1, 'colormap') C = 0 0. . . 0. 5625 0. 6250 0 0. . . 1. 0000 . . . 0. 6250 0. 5625 0. 5000 . . . 0 0. 5625 0. 6250. . . 0. 4375 0. 3750. . . 0 0 0
“colormap” is a property of the figure colormap(cool)
colormap(colorcube)
The same plot as a contour map colormap(jet) contour(XX, YY, ZZ, 100)
… and with a colorbar
Solid shading flat We can change the way the surface displays by changing its shading: >>surf(peaks) %creates 49 by 49 matrix % an plots its values %against x, y indices >>shading flat faceted %default interpolated faceted
Every axes has a property called ‘view’ that controls the azimuth (az) and elevation (el) of the viewpoint To change the viewpoint we use either: view(az, el) or set(axes_handle, ’View’, [az el])
>>view(-37. 5, 30) >>view(0, 0) >>view(-10. 0, 30) >>view(0, 30)
Special 3 d plots contour 3(x, y, z, n) %create n realistic contours interpreting z %as the height from the x y plane. If specified % x and y should have the same size as z >>contour 3(topo, 30) >>axis off
Special 3 d plots We can create a sphere or a cylinder (of radius =1) with little effort >>[x, y, z]=sphere; %will compute the required % N+1 (N=20 by default) coordinates so >>surf(x, y, z) %will plot sphere surface >>axis equal Note: Øsphere without left arguments will plot the surface. Øsphere(n) use n instead of the default of 20
Special 3 d plots To create a cylinder we issue the following command: >>[x, y, z]=cylinder; >>surf(x, y, z)%this creates a basic cylinder of %radius 1
Special 3 d plots We can also create cylinder with reference to a specific profile. We will now generate a cylinder with the esin(t) profile >> t = 0: pi/10: 2*pi; >> [X, Y, Z] = cylinder(exp(sin(t))); >> surf(X, Y, Z)
Graphical User Interfaces Why? Built in UIs Uicontrols GUI programming
Every day examples
GUI examples
Graphic Objects • figure • axes • 2 D-plot • 3 D-plot • axis labels • title GUI objects • pushbutton • toggle • edit • text • menu
Motivation or why GUIs? 1. Enable you to share your work with other people (your advisor/lab mates or grandmother) 2. Easy way to perform repetitive task that need constant user input 3. Create interactive demos to your applications 4. It’s fun…
GUI components Figure window GUI controllers which are divided into two major classes: uimenu (like the File, Edit etc) uicontrols (buttons, lists, radio buttons pop-up list like in any other application) uimenu and uicontrols are children of the figure If an uimenu is implemented as submenu, then it is a child of another uimenu
Interface controllers The UIcontrols are common interface controlers Help us perform specific actions or set the variables for future actions Actions and options are selected by the mouse, some UIcontrols are also editable so we can use the keyboard as well
Interface controllers We can create UIcontrols simply by implementing the following syntax handle_to_UI=uicontrol(‘Property Name’, ’Property Value’);
Interface controllers UIcontrol types are defined by their ‘style’ property: Check box 'checkbox' Toggle button 'toggle' ' Editable text field 'edit' Pop-up menus 'popupmenu' Push button 'pushbutton List box 'listbox' Radio button 'radiobutton' Static text 'text' Slider 'slider' Frame 'frame'
Interface controllers are graphic objects Essential properties: Callback – A string with one or more commands that is executed when the controller is activated. May be empty – ''
Example uicontrol('style', 'pushbutton', 'callback', 'close(gcf)');
Interface controllers are graphic objects Essential properties: Callback – A string with one or more commands that is executed when the controller is activated. May be empty - '' Recommendation – always call a function that does what you want.
Interface controllers are graphic objects Essential properties: Callback – A string with one or more commands that is executed when the controller is activated. May be empty - '' Recommendation – always call a function that does what you want. Tag – a string that may be used as a unique identifier of the controller. h = findobj('Tag', '1');
- Slides: 53