Update GUIDE GUI when radiobutton is selected
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
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!
채택된 답변
Geoff Hayes
2016년 8월 9일
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);
chlor thanks
2016년 8월 9일
편집: chlor thanks
2016년 8월 9일
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.
chlor thanks
2016년 8월 9일
편집: chlor thanks
2016년 8월 9일
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.
chlor thanks
2016년 8월 9일
편집: chlor thanks
2016년 8월 9일
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)
