Refresh value in checkbox upon popmenu

3 Ansichten (letzte 30 Tage)
JB
JB am 31 Aug. 2017
Kommentiert: JB am 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 Kommentare
Birch
Birch am 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 am 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.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Cam Salzberger
Cam Salzberger am 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 Kommentare
Cam Salzberger
Cam Salzberger am 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 am 2 Sep. 2017
Hey Cam. Thanks a lot for your links. I will have a look.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Interactive Control and Callbacks finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by