870 likes | 898 Views
Programming a GUI. Hanan sedaghat pisheh. For calling GUI, we need a function with no inputs or outputs First We create a m.file m file has the same name as the function. Creating the Function. Make sure the function name is the same as the m file ’ s. No input and No output.
E N D
Programming a GUI Hanan sedaghat pisheh
For calling GUI, we need a function with no inputs or outputs First We create a m.file m file has the same name as the function
Creating the Function Make sure the function name is the same as the m file’s. No input and No output
You can use F5 or play buttton to run your rogram Write figure in your function and run it.
Setting Figure Properties Syntax for setting figure properties is: figure('PropertyName',propertyvalue,…)
Color vector value for [R, G, B], where each vector element takes a value in the range [0, 1]. Examples: [0, 1, 0] = GREEN [1, 1, 0] = YELLOW [1, 1, 1] = WHITE [0.5 0.5 0.5] = GRAY [0.5 0.2 0.75] = PURPLE
Position Takes the vector value [x, y, w, l] Each element is a value in the units specified by the figure property ‘units’ x- Distance from left side of the screen y- Distance from bottom side of the screen w- Width of figure (horizontally) l- Length of figure (vertically)
Units Safest bet is to use the property value ‘normalized’. With ‘normalized’ chosen, each element is relative to the screen and takes the value in the range of [0, 1]. [1, 1] [0, 0]
0.45 0.45 0.45 0.25
RANDOM FUNCTION Creates a random number in the range [0, 1]. Can be used in [R, G, B] vector or even [x, y, w, l] vector
UICONTROL Creates edit boxes, text boxes, pushbuttons, sliders, popup menus and more. Syntax: Uicontrol(‘propertyName’,propertyvalue)
UICONTROL Property: ‘Style’ ‘style’ property specifies the UICONTROL type and can have one of the following as its value: 1-pushbutton 7- slider 2- toggle button 8- frame 3- radio button 9-listbox 4-checkbox 10- pop up menu 5-edit 6-text
UICONTROL Property: Position ‘position’ behaves similarly to the FIGURE property, only here the position is taken relative to the figure window. Likewise, ‘units’ is treated in the same vein. [0,0]
We need to give handles for objects so we could reference them later.important Command Get and set command are going to use alot. Syntax: get(handle,’propertName’)
Imagine we want to use the color of figure for the color of the text background So we should get the color of the created figure (with handle “f”)
SET Command Gives pre-existing objects new values for properties. Syntax: set(handle,’propertyName’,propertyvalue) Lets change background color of first text box from green to random.
What if we don’t want a dark background but we still want random one ? Remember: higher values brighter colors
ANSWER: rand*0.5+0.5 gives us values in the range [0.5 1].
Pushbutton Callback pushbutton has the ‘callback’ property name with the property value “@DO1”. This means that whenever the user interacts with the UICONTROL (in our case push the pushbutton), we will execute the function “DO1”.
“varargin”stand for variable argumentsThis is due to the fact that the function has no inputs to it.
Lets try this one : Add the number in the edit box with 5 and displayed on the text box1 Remember: 1-for convert string to numerical value, we use the command STR2NUM 2-use string in set command
Popupmenu list of possibilities which user can choose from them.
Lets try this one: we want to have a popupmenu string and we want the user to choose between squaring and cubing the value in the edit box. Thus when the pushbutton is pressed, the popupmenu value is checked and based on it, the operation performed will be different.
What do you think? Assume we want to have same example as before but this time in addition of pushing button we want an update when user changes the popupmenu
This means we should give the popupmenu a callback function which is the same as pushbutton callback function.
Listbox Its function is very similar to the popupmenu.