MATLAB Answers

Refresh value in checkbox upon popmenu

조회 수: 8(최근 30일)
JB
JB 31 Aug 2017
Commented: JB 2 Sep 2017
The data I have is called in the "checkbox1" as "fulldata" where I have the X and Y values located in a data matrix:
Code:
function popupmenu1_Callback(hObject, eventdata, handles)
function popupmenu1_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function checkbox1_Callback(hObject, eventdata, handles)
fulldata=handles.fulldata;
x1=fulldata(:,1);
x2=fulldata(:,3);
x3=fulldata(:,5);
Y1=fulldata(:,2);
Y2=fulldata(:,4);
Y3=fulldata(:,6);
contents = get(handles.popupmenu1,'String');
popupmenu1value = contents{get(handles.popupmenu1,'Value')};
switch popupmenu1value
case 'plot1'
plot(X1,Y1)
case 'plot2'
plot(X2,Y2)
case 'plot3'
plot(X3,Y3)
end
Dependent on the popupmenu1 selection I want to plot on of the specified plots. The selection is working fine when I first select the value in the popupmenu followed by the checkbox. However, if I change the value of the popupmenu, I have to uncheck and recheck the checkbox to refresh the new selection. Is there a way where the checkbox function is refreshed automatically when I change the popupmenu value, so I dont have to uncheck and recheck it? Thanks a lot...

  댓글 수: 3

Jan
Jan 31 Aug 2017
Of course there will be a way to implement, what you want. You can trigger the code of the checkbox manually also. For a more details answer post the code of the checkbox callback also.
Birch
Birch 31 Aug 2017
Hi Jan Simon. This is all I have. It might be very wrong, but I am very new to matlab GUI. If you have an example or idea I will appreciate it very much.
JB
JB 2 Sep 2017
Hey Jan Simon. I have updated the question to specify how I get my X,Y values. I know the code is a bit clumsy, but I am still a novice in matlab coding. If you have any ideas please let me know.

로그인 to comment.

답변 수 (1)

Cam Salzberger
Cam Salzberger 31 Aug 2017
If you add a callback for the popup menu, you can even just make it call the checkbox callback in there. Or, for better programming practice, create a separate function called "refreshPlot" or something like that, and have both the checkbox's and the popup menu's callbacks call that.
-Cam

  댓글 수: 3

Birch
Birch 31 Aug 2017
It Sounds exactly like what I am looking for, but I have no idea how to do it. I am completely new to matlab GUI coding.
Cam Salzberger
Cam Salzberger 1 Sep 2017
Hey Birch,
I can recommend that you check out some basic tutorials on GUI creation. If you are using an old release, you can check out an introductory demo on GUIDE here.
If you are working with R2016a or later, you could check out GUIDE, or try using App Designer. Here is a webinar demo, and here is a documentation getting-started guide.
Hope that helps!
-Cam
JB
JB 2 Sep 2017
Hey Cam. Thanks a lot for your links. I will have a look.

로그인 to comment.

이 질문에 답변하려면 로그인을(를) 수행하십시오.

제품


Translated by