MATLAB GUI Tutorial - Button Types and Button Group
03 Nov 2007 Quan Quach 70 comments 22,185 views
Introduction
In this three-part Matlab GUI Tutorial, you will learn how to use the different types of buttons available within Matlab GUIs. These button types are: push button, radio button, check box, and toggle buttons. In addition, you will learn how to use the button panel to control a group of buttons.

This tutorial is written for those with little or no experience creating a Matlab GUI (Graphical User Interface). If you’re new to creating GUIs in Matlab, you should visit this tutorial first. Basic knowledge of Matlab is recommended. Matlab version 2007a is used in writing this tutorial. Both earlier versions and new versions should be compatible as well (as long as it isan’t too outdated). Let’s get started!
Part One: The Pushbutton
The push button is a very simple component. When the user clicks on a push button, it causes an action to occur. This action is dictated by the code that is programmed in the push button’s callback function. In this part of the tutorial, we will program the push button to display some text when it is pressed.
-
First, we are going to create the visual aspect of the GUI. Open up Matlab. Go to the command window and type in
guide.
-
You should see the following screen appear. Choose the first option
Blank GUI (Default).
-
Click on
and add one Static Text component to the GUI figure. Next, click on
and add one Push button component onto the GUI figure. -
Double click the Static Text component to bring up the Property Inspector. Change the String property so that there is nothing inside. Change the Tag property to
display_staticText. Similarly, double click on the Pushbutton component and change the String property toDisplay Text!and change the Tag property todisplayText_pushbutton.

-
Here’s what your figure should look like after you add the components and modify them.

-
Save your GUI wherever you please with your desired filename.
-
Now, we are going to write the code for the GUI. When you save your GUI, Matlab automatically generates an .m file to go along with the figure that you just put together. The .m file is where we attach the appropriate code to the callback of each component. For the purposes of this tutorial, we are primarily concerned only with the callback functions. You don’t have to worry about any of the other function types.
Open up the .m file that was automatically generated when you saved your GUI. In the Matlab editor, click on the
icon, which will bring up a list of the functions within the .m file. Select displayText_pushbutton_Callback.

Add the following code to the function:
%display "Hello Wordl!" in the static text component when the %pushbutton is pressed set(handles.display_staticText,'String','Hello World!');
-
Now that we’ve completed both the visual and code aspects of the GUI, its time to run the GUI to make sure it works before we move on. From the m-file editor, you can click on the
icon to save and run the GUI. Alternatively, from the GUIDE editor, you can click on the
to launch the GUI. The GUI should appear once you click the icon. Now try clicking on the button to make sure that Hello World! appears on the GUI. 
And that’s it. Those are the basics of using the Push button component. Now we’re ready to move onto the Check box component.
Part Two: The Check Box
The Check Box component has two states, checked and unchecked. These components are usually used to control options that can be turned on and off. In this part of the tutorial, we will add the functionality of making the display text become bold or unbolded.
-
The first thing we need to do is to add a Check Box Component to the GUI figure that we were just working with. So if you closed GUIDE, reopen it again. Once you have GUIDE opened again, Click on
and add one Check Box component to the GUI figure. -
Double click the Check Box component to bring up the Property Inspector. Change the String property to
Bold. Change the Tag property tobold_checkbox.

-
Here’s what your figure should look like after you add the Check Box component and modify it.

-
Add the following code to the bold_checkbox_Callback function:
%checkboxStatus = 0, if the box is unchecked, %checkboxStatus = 1, if the box is checked checkboxStatus = get(handles.bold_checkbox,'Value'); if(checkboxStatus) %if box is checked, text is set to bold set(handles.display_staticText,'FontWeight' , 'bold'); else %if box is unchecked, text is set to normal set(handles.display_staticText,'FontWeight', 'normal'); end
Note: The bold_checkbox_Callback function triggers when the user activates the check box AND when the user deactivates the check box.
-
Now that we’ve completed both the visual and code aspects of the GUI, its time to run the GUI to make sure it works before we move on. Try checking and unchecking the Check Box component to make sure that the text “Hello World!” is being bolded and unbolded.

And that’s it. Those are the basics of using the Check Box component. Now we’re ready to move onto the Button Group, which is the most challenging part of this tutorial.
Part Three: Radio Buttons, Toggle Buttons, and Button Group Panel
Radio buttons and Toggle buttons are used exactly the same way that check boxes are used in Matlab GUIs, so we won’t go over how to use them. But there is one special case that needs to be covered. When either radio buttons or toggle buttons are used in conjunction with the button group panel, they exhibit mutually exclusive behavior. Simply put, this means that only one radio button or one toggle button can be selected at a time. This behavior can come in very useful for some GUIs. Since radio buttons and toggle buttons are identical in their functionality, what is said about one, is true for the other. Thus, only radio buttions will be discussed from here on out.
In this part of the tutorial, we will create a button group that will allow you to choose between different font sizes for the display text.
-
The first thing we need to do is to add a Button Panel component to the GUI figure that we were just working with. So if you closed GUIDE, reopen it again. Once you have GUIDE opened again, click on
and add one Button Panel component to the GUI figure. Make sure it’s large enough to fit in three radio buttons. Next, click on
and add three radio buttons onto the button group panel. -
Double click on the first Radio Button component to bring up the Property Inspector. Change the String property to
8. Change the Tag property tofontsize08_radiobutton.
Next, double click on the second Radio Button component, and change the String property to
12, and change the Tag property tofontsize12_radiobutton.Next, double click on the third Radio Button component, and change the String property to
16, and change the Tag property tofontsize16_radiobutton.Finally, double click on the button group panel and change the Tag property to
fontSelect_buttongroup. You should also change the String property for the button group panel toFontsize. -
Here’s what your figure should look like after you add the components and modify them.

-
Before we move on, we should check the hierarchical structure of the GUI figure. Click on the
icon and the followinging should appear:
Make sure that the three radio buttons are one hierarchy below the button group icon.
-
Add the following line of code to the opening function. In this tutorial example, it is named button_tutorial_OpeningFcn function. Yours will be the name of the file you saved it as, followed by “_OpeningFcn”.
set(handles.fontSelect_buttongroup,'SelectionChangeFcn',@fontSelect_buttongroup_SelectionChangeFcn);
Make sure the previous line was added right before the line:
guidata(hObject, handles);
Next, add the following function at the very end of the .m file.
function fontSelect_buttongroup_SelectionChangeFcn(hObject, eventdata) %retrieve GUI data, i.e. the handles structure handles = guidata(hObject); switch get(eventdata.NewValue,'Tag') % Get Tag of selected object case 'fontsize08_radiobutton' %execute this code when fontsize08_radiobutton is selected set(handles.display_staticText,'FontSize',8); case 'fontsize12_radiobutton' %execute this code when fontsize12_radiobutton is selected set(handles.display_staticText,'FontSize',12); case 'fontsize16_radiobutton' %execute this code when fontsize16_radiobutton is selected set(handles.display_staticText,'FontSize',16); otherwise % Code for when there is no match. end %updates the handles structure guidata(hObject, handles);
-
Notice that the callback functions for the radio buttons were not automatically generated by Matlab. This is completely normal. Each time a button is selected within the Button Group Panel component, the function defined within the SelectionChangeFcn property of Button Group Panel component is called. The line of code that was added in the opening function specifies the callback function when a button within the button group is selcted. The selection change function is then defined at the end of the .m file.
-
Now that we’ve completed both the visual and code aspects of the GUI, its time to run the GUI again. Try clicking on all of the buttons to make sure they perform their function correctly. Specifically, make sure that the font size changes accordingly.

And that’s it. Those are the basics of using the different buttons within the Matlab GUI.
Download Source Files
Source files can be downloaded here.
This is the end of the tutorial.
70 Responses to “MATLAB GUI Tutorial - Button Types and Button Group”
Leave a Reply
Include MATLAB code in your comment by doing the following:
<pre lang="MATLAB">
%insert code here
</pre>


A very good tutorial for the beginners. Thanks.
Hi Quan Quach
I think you forget to mention to change the Tag of the button group to fontSelect_buttongroup in the totorial.
Thanks TongTong for pointing that out, I added in the edit.
Amazing , that is what a beginner needs. congratulations and keep up the good work.
The best Matlab GUI tutorials I’ve found on the internet!!! It makes my life easier, when learning GUI
Many thanks!
A very good tutorial, thanks! Do you know if there’s any similiar website where I can find more advanced examples? Thank you again!
Josef:
The mathworks blogs section has some pretty good stuff, so you can give them a shot. Otherwise, I really don’t know of a similar website . . . yet. Good luck.
Thanks always! How do I code the pushbutton into being activated via pressing the keyboard’s “Entry” key in addition to mouse clicking?
Jim:
Here is a relatively simple example of how this can be done. Download the files here.
The example is an adder GUI that will add two numbers together when you press the enter key or when you press the “add” pushbutton.
Good luck. Stay tuned for the tutorial on this topic.
Quan
Hello!
and thank you very much, the info in this page was very usefull and I think it’s fair to let you know it.
anyway, I implemented my code just like you said here, and it works very good, except for the case when I don’t change the initial position of the buttons… in that case it never enter to the selectionchangefnc, and therefore, it never performs what I need.
am I missing something?
thank you very much in advanced.
Benja
This has been a great help to get me started. Thanks for doing it.
Hi, just tried this using matlab 7 but I do not seem to get the option to change the String property for the Button Panel i.e. its not on the list? Any idea how I can add?
Hi froggy,
I don’t have that version installed, but i would imagine there is some sort of option to change the title on the button group panel. Unfortunately, I do not know how to do it since I use version 2007a.
Quan
Thank you very much. This example helps greatly.
I’d like to suggest that Matlab makes GUI more easier for using by doing the following
1. After click button group, asking for No. of button in the group, then generate the group with buttons automatically.
2. Generate selectionChangeFcn automatically when saving.
this tutorial is very useful
Thank you so much for this tutorial… It is very helpful..
Thank you very much,
This tutorial was very uesfull. After reading this page I implemented my code jiust like you said, and it works very good.
Hallo Mr Quan
Greetings . I like your clear succint style. As to the Button group
where exactly in the massive Simulink documentation does one find the instruction to be entered in the opening function.(Section 5 of part3). The problem here is suppression of individual callbacks for the radio buttons to ensure exclusivity i.e one button is active at a time. The Eventdata thing is supposed to be in a future version of Simulink. Could you please elaborate on function_handles and scope of variables in the context! Will look forward to your reply
All the best
udaya
Udaya,
Try these links for a brief introduction of handles:
http://www.blinkdagger.com/matlab/matlab-gui-tutorial-a-brief-introduction-to-handles
Try this one for an intro on how to share data between callbacks
http://www.blinkdagger.com/matlab/matlab-gui-tutorial-sharing-data-among-callbacks-and-sub-functions
Thank u very much,
I have a doubt in setting the ‘Value’ property of Check Box in MATLAB GUI, can u pls help me in solving the same.
My question is:
How to change the state of a check box by programmatically by setting the check box ‘Value’ property ???
I tried with following two methods and both are not working:
function GUI_OpeningFcn(hObject, eventdata, handles, varargin)
global hObject_checkbox
1 . set(hObject_checkbox, ‘Value’, ‘Max’);
or
2 . set(hObject_checkbox, ‘Value’, 1);
Actually I want to set the Check Box property from different GUI (Main/ Parent GUI) before calling the Sub GUI, How do i do it????
PLs reply as early as possible, it is very urgent requirement to me.
Thanks and Regards,
Ashwini
Bonjour M .Quan
Thanks for the references to your tutorials. My questions were not quite at that user level but more on the use of function handles , event detections (past and current like swich closures), reference cells. The line to be inserted in the opening function (your
button_tutorial part 3 section 5) does replace individual callbacks for the radio buttons by one ‘main’ with subfunctions chosen by ,’current’ tags. I feel a detailed tutorial on these topics will be of interest to many. Keep up the good work!
udaya
I don’t know how to write the “Callback”?
Great tutorial…exactly what I was looking for…Thanks
Hi,
I used a ‘calculate’ pushbutton to calculate some values. When i run the gui and press the calculate button, the whole gui looks blocked. None of the buttons worked after that. Do I have to change something in the property inspector to correct it?
hi,
l used push button for showing my succive data, i don’t how to make the button , can l have fu rther information about it.
thanks,
Hi,
thanks, really its a great toutorial .
Hey, I am doing the same thing as you, but it doesn’t work.
Look at my code:
function varargout = test_button_group(varargin)
% TEST_BUTTON_GROUP M-file for test_button_group.fig
% TEST_BUTTON_GROUP, by itself, creates a new TEST_BUTTON_GROUP or raises the existing
% singleton*.
%
% H = TEST_BUTTON_GROUP returns the handle to a new TEST_BUTTON_GROUP or the handle to
% the existing singleton*.
%
% TEST_BUTTON_GROUP(’CALLBACK’,hObject,eventData,handles,…) calls the local
% function named CALLBACK in TEST_BUTTON_GROUP.M with the given input arguments.
%
% TEST_BUTTON_GROUP(’Property’,'Value’,…) creates a new TEST_BUTTON_GROUP or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before test_button_group_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to test_button_group_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE’s Tools menu. Choose “GUI allows only one
% instance to run (singleton)”.
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help test_button_group
% Last Modified by GUIDE v2.5 17-Jul-2008 01:38:31
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct(’gui_Name’, mfilename, …
‘gui_Singleton’, gui_Singleton, …
‘gui_OpeningFcn’, @test_button_group_OpeningFcn, …
‘gui_OutputFcn’, @test_button_group_OutputFcn, …
‘gui_LayoutFcn’, [] , …
‘gui_Callback’, []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% — Executes just before test_button_group is made visible.
function test_button_group_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to test_button_group (see VARARGIN)
% Choose default command line output for test_button_group
handles.output = hObject;
% Update handles structure
set(handles.fontSelect_buttongroup,’SelectionChangeFcn’,@fontSelect_buttongroup_SelectionChangeFcn);
guidata(hObject, handles);
% UIWAIT makes test_button_group wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% — Outputs from this function are returned to the command line.
function varargout = test_button_group_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
function fontSelect_buttongroup_SelectionChangeFcn(hObject, eventdata)
%retrieve GUI data, i.e. the handles structure
handles = guidata(hObject);
switch get(hObject,’Tag’) % Get Tag of selected object
case ‘fontsize08_radiobutton’
%execute this code when fontsize08_radiobutton is selected
set(handles.display_staticText,’FontSize’,8);
case ‘fontsize12_radiobutton’
%execute this code when fontsize12_radiobutton is selected
set(handles.display_staticText,’FontSize’,12);
case ‘fontsize14_radiobutton’
%execute this code when fontsize16_radiobutton is selected
set(handles.display_staticText,’FontSize’,16);
otherwise
% Code for when there is no match.
end
%updates the handles structure
guidata(hObject, handles);
Let me know please, I need to get this done!!
Thanks!
Edvier, I don’t know what your error is.
In addition, we are not in the business of debugging code. You can download the source file for this GUI to troubleshoot. Maybe you didn’t name your buttons correctly or set up the button panel incorrectly.
Goodluck debugging. If you have specific questions, come back and ask them!
Hello,
How can i increase the size of the tick in the checkbox?
Thanks,
Smith
Hi,
I tried to run the source code downloaded above. But there are some error occurred. The errors are as follows:
_______________________________________________________________________
There is no ‘SelectionChangeFcn’ property in the ‘uipanel’ class.
Error in ==> button_tutorial>button_tutorial_OpeningFcn at 58
set(handles.fontSelect_buttongroup,’SelectionChangeFcn’,@fontSelect_buttongroup_SelectionChangeFcn);
Error in ==> gui_mainfcn at 166
feval(gui_State.gui_OpeningFcn, gui_hFigure, [], guidata(gui_hFigure), varargin{:});
Error in ==> button_tutorial at 42
gui_mainfcn(gui_State, varargin{:});
_______________________________________________________________________
P/S: How to solve this error?
Thanks.
Regards,
Jessie
Jessie,
Are you using an old version of MATLAB? It works fine for me on 2006 and 2007. (I assume it works on 2008 too)
Quan
I think my Matlab version is 2005 one. Version 7.1.0.246 (R14) Service Pack 3
i want to control the group of radio button with a button
how can i do this?can i use selectionchangefcn here?
Very nice tutorial.
I hope there are something more about radio button properties.
Hi
on my computer thís program works fine, but only if i type in guide and start the figure from there (the green button). If I start the figure directly nothing happens at all.
I tried it on 3 computers with matlab 2007 an 2008.
Does any know how to help me?
Hello Quan,
This is slightly irrelevant, but you seem to be on the ball. I would like a push button such that each time it is pushed, my variable, let’s call it “counter” increases by 1. My problem is that I would like this to be a global variable, but I don’t know where [in the m-file code] to first assign it a value. I want the value of counter to revert back *only* when I run the code, but not every time a callback function is called (via ui inputs). Any thoughts? Thanks very much for all your work.
Liam
Many thanks. The MATLAB help documentation does not mention the need for adding the “set” statement for the button panel in the opening function. Their button panel example does not have it yet somehow works. Your tutorial really got me off dead center.
George,
Glad it helped you. Are you related to Keifer by any chance?
Then, the real difference between radio buttons and toggle buttons is merely aesthetical? Am I wrong?
Hehe, in that case, it’s always nice to check that there is humanity behind the big wizard of Oz!
Great tutorial, as always, Quan!
Thanks
I hope to go on on this way
@Mr Quan:ur tutorials are great.am just learning the GUI for the last 5 dasy and ur tutorials have been verry helpful.
my question is that while suing the function
#function fontSelect_buttongroup_SelectionChangeFcn(hObject, eventdata)
#%retrieve GUI data, i.e. the handles structure
#handles = guidata(hObject);
#switch get(eventdata.NewValue,’Tag’)
why is this eventdata.NewValue is used here? can u please explain me this ‘eventdata.NewValue’ in details?
also
why cant we use
# switch get (handles.fontSelect_buttongroup,’Tag’)
or
# switch get(hObject,’Tag’)
here?
Please reply fast Sir.
@Edvier
i guess ur code doesnt work because u have used hObject and not eventdata.NewValue.
hello,
how i can take the output for button as input to othor button
for example:
there are 2 buttons one for select image the other for store image, if i click select image after i select the image i will click store image to this image. when i did that the store button display an error msg there is no image select.
thanks
Hi, Thanks for very good tutorial. But I’m wondering why I received this error for part 3 tutorial?
Hope to have some advice from you.Thanks again.
There is no ‘SelectionChangeFcn’ property in the ‘uipanel’ class.
Hi Quan,
The tutorials have helped immensely. I have been working on a button group which passes a value between two GUIs. To elaborate a bit, I call up the main GUI and set a value for units (whether English or SI). I then want to change the properties of a material and call up the sub GUI to do so. My goal is to have the sub GUI display the same units as the main GUI. To do so, I have to pass the value from the main to the sub. I have used your examples and managed to pass the values. My sub now receives the units value from the main. I now want to have the sub display the proper units graphically when it is called, rather than the default.
This appears to be the same request as Ashwini (#20 in the chat). I did notice that after running on the variable value passing all day, I had to shut the matlab program down and restart to pass the value correctly. Since I had no “clear” function in my routine, this makes sense. Hopefully this bit of advice helps someone.
So how do I set the initial value of the button group before I use the ‘SelectionChangeFcn’ to the value I passed so I don’t just see the default button highlighted at boot-up of the dialog?
Thanks.
Hi Quan,
I solved the issue. It always looks simple when you get to the right answer. Here is what I did.
In the opening function of the sub GUI,
1. I access the handle from the main GUI to get value being passed.
2. use the “set” function to access the ‘SelectionChangeFcn’ as noted in your tutorials.
3. then write an “if” routine as follows:
if (handles.UnitsTracker == 1)
set(handles.UnitsChoice_English_radiobutton,’Value’,0)
set(handles.UnitsChoice_SI_radiobutton,’Value’,1)
end
% Update handles structure
guidata(hObject, handles);
The default is ‘0′. So I only enter this routine if I am passing a ‘1′.
Hopefully this helps some other users.
Quick question. There is the Opening function to execute code just BEFORE the figure window appears. But I have four plots that I want to modify in the beginning. Any there any way to add code to change them just AFTER the figure appears? I get an error trying to adjust the axes in the Opening Function because the axes don’t exist yet. Thanks for the help.
hi
i wonder…i want to interface the GUI with microsoft word and pdf..can i make these function through pushbutton?or…any suggestion to interface these 2 things?
@ aaliyah
you’ll need to use actxserver. You can find more about it in the MATLAB documentation.
hi, i tried to use the radiobutton for my project, according to this tutorial, but the MATLAB give me this error:
There is no ‘SelectionChangeFcn’ property in the ‘uipanel’ class.
can anyone tell me what that means?
FYI, in my m-file, i put:
set(handles.database_buttongroup,’SelectionChangeFcn’,@database_buttongroup_SelectionChangeFcn);
since my tag for the radiobutton group is ‘database_radiobutton’
i’m really new to GUI, so pardon me if this is just a silly question.
thanks in advance…
^ sorry, i mean, my tag for the radiobutton group is ‘database_buttongroup’
typo.
hello,
I am creating a program where i can calculate body mass index, and i am including an option where the user gets to choose the units (US or SI) through radio buttons. but for US units, i should multiply the formula by 708 (coefficient). how can i make the program multiply by 708 when the user chooses us units and not to when the user chooses si units?
thanks for the help
Elie
Elie,
Please look at the third part of this tutorial, I believe it will show you how to do exactly what you want:
http://blinkdagger.com/matlab/matlab-gui-tutorial-buttons-button-group/3
Quan
Hello,
I am creating a GUI program that calculates body mass index (bmi) and i want it to classify the user in a range according to the bmi value. (e.g. if bmi is < 18 — normal, if bmi between 18 and 24 — overweight …) .
any idea how i can do that ?
Thanks !!!!!!!
Elie
Thank you very very very very much!!!
[...] Tutorial - Slider MATLAB GUI Tutorial - Pop-up Menu MATLAB GUI Tutorial - Plotting Data to Axes MATLAB GUI Tutorial - Button Types and Button Group MATLAB GUI Tutorial - A Brief Introduction to handles MATLAB GUI Tutorial - Sharing Data among [...]
Hellow ,
Shall I ask you in which math ver does support this ?
My one doesn’t display the button group icon from ‘guide ‘ !.
So I coudn’t complete your advice with m file .
If then , can I make any sentence to simulate as like your did with goup icon ?
Thanks with your advice in advance .
Brs,
lichel
FUNNY….GUYS!
I tried really hard to understand the MATLAB help with radio buttons and suddenly thanks to you, all becomes crystal clear. Bless you!
Thanks for the wonderful tutorial. I suggest a minor change: The buttongroup panel does not have a String property. I think you meant Title..
Thanks!
I really like your tutorials. They are structured in an understandable way. Thanks!
Hey.
Thanks for the turorial. It gives ad great introduction. I was wondering how is it possible to move or create a pushbutton or edit in a program. For example, by pressing button A, button B and C appears. But by pressing Button D, button E and F appears.
Any ideas anyone??
Have a great weekend.
Hi, I have a question about using button groups within panels. When I create a GUI with a button group within a panel, none of the buttons show up with a callback (i.e. function radiobutton1_Callback(hObject, eventdata, handles) doesn’t show up in the GUI’s m-file). I just want the buttons to modify what’s in an Edit Text box. Is there a simple way to do this? Any advice would be greatly appreciated.
Hallo,
i have a question regarding to the function set(). How can i assign with this function strings, for instance: set(handles.text1,’String’,hallo) ? So i want to transfer ‘hallo’
Hi Quan
Many thanks for the tutorials
I have one question about my program.
I have some variables for my program and One of the variable value I am getting from the Button Group (three Radio Buttons). I want to assign a value depending upon the radio button selected by user.
I have used these lines to define the variable so I can use in my function called by a Push Button..
And I want to extract this value to call my main function using Push button
But Every time I got the error msg.
Please help me in this regard
Hope to hear from you soon
Saurabh
Hi Quan
Many thanks for the tutorials.
I have one question about my program.
I have some variables for my program and One of the variable value I am getting from the Button Group (three Radio Buttons). I want to assign a value depending upon the radio button selected by user.
I have used these lines to define the variable so I can use in my function called by a Push Button..
And I want to extract this value to call my main function using Push button
But Every time I got the error msg.
Please help me in this regard
Hope to hear from you soon
Saurabh
Hi Saurabh,
I think I see your issue in this code (and same issue in your pop-up menu question). In your switch statement, you’re setting the button group ‘String’ value to something. You don’t want to be altering the ‘String’. For the pop-up menu, the ‘String’ is the set of options in your pop-up menu (each ‘case’). You’re essentially overwriting in each block of code by writing:
To fix this, change your variable to something else. You can even use your millingmode variable.
then you shouldn’t need that extra line at the bottom. If you want this value to be accessible in other functions, just attach it to your handles (even though this can be bad form for more complex code, see http://blinkdagger.com/matlab/matlab-global-variables/ )
instead of:
millingmode=1;make it:
That should fix both your current errors! No promises about others though ^_^
-Zane
me parece muy bueno su portal , ojala ubiera mas de estos, estoy preparando una interface grafica para un trabajo y no se aun nada de matlap peroparece ser facil,
Is there a way to change the GUI display depending on the Radio button chosen? For instance, I am trying to let the user select a full frame, subframe, or pixel value. In which case, for the full frame, they would not need to provide an input, for the subframe, they would need to provide a range of x and y values, and then for a pixel they would provide a pixel locaiton.
HNU,
One idea would be to set the ‘visibility’ property of each of the buttons you want to appear depending on the radio button. You can change the visibility by using:
You can use a case/switch function for each radio button option and change the visibility of each button you want active/hidden. this may mean you’ll have overlapping buttons on your GUI editor window, but it won’t matter if you code it right so only the desired buttons appear at any given time.
Good luck,
Zane