Update GUIDE GUI when radiobutton is selected
显示 更早的评论
I made a radiobutton group in my GUI made in GUIDE, but cannot find a callbackFcn for the radiobuttons in matlab automatically generated script, so I put the my radiobuttons code inside a function that is called by a listbox callback. Now is issue is, when I make a new selection in the radiobuttons group, my GUI only updates after I re-select what is selected earlier in the listbox.
How can I better incorporate the radiobutton code with my m-file in this case? I want my GUI to update whenever I make a new selection in the button groups... Thank you for reading, I really appreciate it!
采纳的回答
chlor - in the GUI GUIDE editor, right-click on the radio button group to bring up its pop-up menu. Select *View Callbacks -> SelectionChangeFcn*. This will put that callback within your *.m file. This callback will fire whenever you select a radio button from within this group.
12 个评论
Thank you Geoff! I used this callback and initiated my button selection in the OpeningFcn as:
(since I have a listbox that takes the output of my buttongroup to generate a plot)
set(handles.buttongroup,'SelectedObject',handles.button1)
however, it gives me error that handles.read is non-exist field
so I tried to add this in my listbox callback
handles.read = get(handles.buttongroup, 'SelectedObject')
But it gives me the new error:
Cell contents reference from a non-cell array object.
Am I doing something wrong here? Can you please also give me a little advice on how to fix my code here? I just started learning to use buttongroup and I really appreciate your comment!!
The line
set(handles.buttongroup,'SelectedObject',handles.button1)
can't possibly be giving an error related to handles.read being a non-existent field as it isn't attempting to access that field. It might be easier to post all relevant code.
function plot_OpeningFcn(hObject, eventdata, handles, varargin)
set(handles.buttongroup,'SelectedObject',handles.button1)
%something
guidata(hObject, handles);
function buttongroup_SelectionChangeFcn(hObject, eventdata, handles)
Mode = get(handles.buttongroup, 'SelectedObject');
View = get(Mode, 'String');
switch View
case 'View Type 1'
hi = handles.hi;
case 'View Type 2'
hi = handles.hi;
%do something to "hi"
hi=new_hi;
end
hi = handles.read %assign "hi" to new handle "handles.read" that will be used in listbox_Callback to pass down to func1(handles)
guidata(hObject, handles);
function listbox_Callback(hObject, eventdata, handles)
listbox_index=get(hObject, 'Value');
switch listbox_index %this creats "handles.hi" that will be used as input for buttongroup_SelectionChangeFcn
case 1
%do something
handles.hi=hi;
case 2
%do something else
handles.hi=hi;
end
handles.read = get(handles.buttongroup, 'SelectedObject')
func1(handles); %func1 is another function that I created use input "handles.read"
guidata(hObject, handles);
Thanks for commenting Adam, I apologize if the code I posted is confusing, I try to simplify the code to make easier read, I hope this explains what you were asking...
This line seems odd, especially its seemingly doing the opposite to what the comment says it is:
hi = handles.read %assign "hi" to new handle "handles.read" that will be used in listbox_Callback to pass down to func1(handles)
handles.read will presumably not exist at the point unless the listbox has been interacted with.
Silly me! I changed the hi = handles.read to handles.read = hi, now it is only giving me the error
Cell contents reference from a non-cell array object.
Would this be the way I get "handles.read" in function listbox_Callback is inappropriate? The "handles.read" I am trying to get should be a cell array of strings.
Sorry to bother you again. This is my current code for the buttongroup Callback if it may be the issue that I have not been able to figure out...
function buttongroup_SelectionChangeFcn(hObject, eventdata, handles)
a = handles.a;
b = handles.b;
Mode = get(handles.buttongroup, 'SelectedObject');
View = get(Mode, 'String');
switch View
case 'View Type 1'
set(handles.T2, 'Value', 0)
set(handles.T3, 'Value', 0)
hi = handles.hi; %"handles.hi" is taken from listbox Callback
case 'View Type 2'
set(handles.1, 'Value', 0)
set(handles.3, 'Value', 0)
hi = handles.hi;
x = false(size(hi));
for n=1:numel(a)
x = x | cellfun(@isempty,strfind(hi,a{n}));
end
hi(x) = [];
case 'View Type 3'
set(handles.1, 'Value', 0)
set(handles.2, 'Value', 0)
hi = handles.hi;
x = false(size(hi));
for n=1:numel(b)
x = x | cellfun(@isempty,strfind(hi,b{n}));
end
hi(x) = [];
end
handles.read = hi
guidata(hObject, handles);
Are you trying to use the "read" field of handles as a global variable? Or is "read" the tag of some other control. Why do you think it should have a value before you ever start using it? It only will have a value if you have a control called "read", not if you're using it as a global variable but never assigned anything to it.
I am trying to assign the cell array "hi" to "handles.read" as a global variable that can be shared by all other callbacks. I have done similar things in other Callbacks and it has worked... Now I am confused again...
What about the first time through, when handles.hi does not have a value yet and you try to use it? Also, you should initialize hi just in case none of the switch cases are met.
I am posting a new question http://www.mathworks.com/matlabcentral/answers/299055-listbox-buttongroup-callbacks-error-in-guide-made-gui
I apologize that I kept the thread so long... Thank you all for commenting under my thread and kept me going and wondering!!
chlor thanks
2016-8-10
编辑:chlor thanks
2016-8-10
Sorry! I didn't see your comment earlier, Image Analyst. Do you mean handles.hi created in listbox_Callback? I believe it has a value, because I tried to skip the buttongroup_SelectionChangeFcn and use handles.hi directly and it hass been working fine with no errors. The issue starts after I try to use buttongroup_SelectionChangeFcn to further categorize handles.hi into handles.read and pull the new variable handles.read back into listbox_Callback for func1.
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
