GUI: how to configure radio buttons to activate/grey out a set of checkboxes?

12 ビュー (過去 30 日間)
geomod
geomod 2011 年 8 月 30 日
Hello, I'm discovering the MATLAB GUI possibilities. Aim: to provide a user with a GUI to select some parameters that are necessary for running a program code. Specific: how do I configure the action applied to a set of 2 mutually exclusive radio buttons so that they activate or grey out a set of checkboxes. So, for instance, when the user selects the 'On' radio button, a set of checkboxes must be enabled. Can someone help me with this?
Thanks in advance!

採用された回答

Paulo Silva
Paulo Silva 2011 年 8 月 30 日
Using GUIDE
  1. Put one Button Group on your GUI
  2. Put two radiobutton inside the Button Group (that makes them mutually exclusive)
  3. Put the checkboxes on your GUIDE
  4. Click on the first radiobutton with your mouse right button, View Callbacks -> Callback
  5. MATLAB takes you to the m file of the GUI, now you can put the code that runs when you choose that radiobutton
By grey out you mean that the checkboxes are disabled (you can't check them), do this
set(handles.checkbox1,'Enable','off') %disable checkbox1
Do the same for every checkbox you want to disable.
Now to re enable them do the same steps for the other radiobutton but the code is:
set(handles.checkbox1,'Enable','on') %enable checkbox1
  3 件のコメント
Paulo Silva
Paulo Silva 2011 年 8 月 31 日
hmmm I can adjust individual callbacks just fine (MATLAB 2008b), make sure that you are not clicking on the button group instead of the radiobutton when clicking.
geomod
geomod 2011 年 9 月 1 日
Well, when I hit Callback, a GUIDE dialog appears:
"Button group <tag> manages the Callback of this on.
To customize the behavior when the selected button in the button group changes, modify its SelectionChangeFcn callback."

サインインしてコメントする。

その他の回答 (2 件)

geomod
geomod 2011 年 9 月 1 日
A second question in the line of the first one...
I have a checkbox and when it's marked a axes object shows image A, when it's not marked that same axes object shows an image B. Image A & B have the same size. How do I configure this callback? I now have:
if get(hObject,'Value') == 1
set(handles.axes2, -?- ); % show image A
else
set(handles.axes2, -?- ); % show image B
end
Thanks!
  2 件のコメント
Paulo Silva
Paulo Silva 2011 年 9 月 1 日
What you want to do is to show the image not change some axes property
axes(handles.axes2) %select axes2, it becomes the current axes
if get(hObject,'Value') == 1
image(imageA) %or whatever code you have to show the image
else
image(imageB)
end
geomod
geomod 2011 年 9 月 1 日
Another nice answer. Thank you!

サインインしてコメントする。


geomod
geomod 2011 年 9 月 2 日
OK, I've been trying, but without success. What I have: a GUI with several choices to be made by selecting radiobuttons, ticking checkboxes and values from edit text fields. What I want: collect the values and pass them all via varargout to the evoking function when hitting a confirmation button.
If I for example do this:
varargout{1} = get(handles.edit1);
stated in the _OutputFcn, I get this error:
---
??? Attempt to reference field of non-structure array.
Error in ==> buttongroup>buttongroup_OutputFcn at 85 varargout{1} = get(handles.edit1);
Error in ==> gui_mainfcn at 263 [varargout{1:nargout}] = feval(gui_State.gui_OutputFcn, gui_hFigure, [], gui_Handles);
Error in ==> buttongroup at 40 [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
---
Suggestions?

カテゴリ

Help Center および File ExchangeSubplots についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by