Refresh value in checkbox upon popmenu
2 ビュー (過去 30 日間)
古いコメントを表示
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
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.
回答 (1 件)
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
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
参考
カテゴリ
Help Center および File Exchange で Interactive Control and Callbacks についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!