2. Working with Callbacks in GUIDE
How to Use the Example Code
Push Button
Toggle Button
Radio Button
Check Box
Edit Text
Slider
Topics:
List Box
Pop-Up Menu
Panel
Button Group
Menu Item
Table
Axes
6. Radio Button & Check Box
if (get(hObject, 'Value' ) == get(hObject, 'Max' ))
display( 'Selected' );
else
display( 'Not selected' );
end
7. Edit Text
input = get(hObject, 'String' );
display(input);
Strings
Retrieve Numeric Values
input = str2double(get(hObject, 'string' ));
if isnan(input)
errordlg( 'You must enter a numeric value' , 'Invalid Input' ,
'modal' )
uicontrol(hObject)
return
else
display(input);
end
8. List Box & Pop-Up Menu
items = get(hObject, 'String' );
index_selected = get(hObject, 'Value' );
item_selected = items{index_selected};
display(item_selected);
9. Panel
display( 'Mouse button was pressed' );
Resize the Window and Panel
By default, GUIDE GUIs cannot be resized, but you can
override this behavior by
selecting Tools > GUI Options and
setting Resize behavior to Proportional.
set(hObject, 'Units' , 'Points' )
panelSizePts = get(hObject, 'Position' );
panelHeight = panelSizePts(4);
set(hObject, 'Units' , 'normalized' );
newFontSize = 10 * panelHeight / 115;
texth = findobj( 'Tag' , 'text1' );
set(texth, 'FontSize' ,newFontSize);
10. Button Group
Button groups are similar to panels, but they also manage
exclusive selection of radio buttons and toggle buttons.
When a button group contains multiple radio buttons or
toggle buttons, the button group allows the end user to
select only one of them.
switch get(eventdata.NewValue,'Tag')
case 'radiobutton1'
display( 'Radio button 1' );
case 'radiobutton2'
display( 'Radio button 2' );
case 'togglebutton1'
display( 'Toggle button 1' );
case 'togglebutton2'
display( 'Toggle button 2' );
end
.
14. • In the button write this code
a= str2num(get(handles.edit1,'string'));
b= str2num(get(handles.edit2,'string'));
c=a+b;
set(handles.text3,'string',c);
• In the button write this code
a= str2num(get(handles.edit1,'string'));
b= str2num(get(handles.edit2,'string'));
c=a-b;
set(handles.text3,'string',c);
15. • In the button write this code
a= str2num(get(handles.edit1,'string'));
b= str2num(get(handles.edit2,'string'));
c=a*b;
set(handles.text3,'string',c);
• In the button write this code
a= str2num(get(handles.edit1,'string'));
b= str2num(get(handles.edit2,'string'));
c=a/b;
set(handles.text3,'string',c);