Refresh value in checkbox upon popmenu

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 2017년 8월 31일
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 2017년 8월 31일
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 2017년 9월 2일
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.

댓글을 달려면 로그인하십시오.

답변 (1개)

Cam Salzberger
Cam Salzberger 2017년 8월 31일

1 개 추천

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 2017년 8월 31일
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 2017년 9월 1일
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 2017년 9월 2일
Hey Cam. Thanks a lot for your links. I will have a look.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

제품

질문:

JB
2017년 8월 31일

댓글:

JB
2017년 9월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by