Refresh value in checkbox upon popmenu

3 次查看(过去 30 天)
JB
JB 2017-8-31
评论: JB 2017-9-2
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 个评论
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
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 个评论
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by