I am working on a GUI using matlab r2015b version with multiple panels on it. What im trying to do is only show the panel that is selected on the popup menu (shown on the last picture). However, when i tried to run it, only one panel is showing even though i selected other option. No errors such as reference to non-existent field exist. It only works on the Newtons second law and Newton law of cooling, but on the other two panels, it wont work. Is it a glitch? should i upgrade to 2018 version? or am i missing a small detail? Thanks :)
contents = cellstr(get(hObject,'String'));
popupmenu1 = contents(get(hObject,'value'));
if strcmp (popupmenu1,'Newtons Second Law of Motion')
set(handles.second, 'Visible', 'on');
set(handles.mixture, 'Visible', 'off');
set(handles.logistic, 'Visible', 'off');
set(handles.cooling, 'Visible', 'off');
elseif strcmp (popupmenu1,'Mixture Problem')
set(handles.second, 'Visible', 'off');
set(handles.mixture, 'Visible', 'on');
set(handles.logistic, 'Visible', 'off');
set(handles.cooling, 'Visible', 'off');
elseif strcmp (popupmenu1,'Logistic Growth')
set(handles.second, 'Visible', 'off');
set(handles.mixture, 'Visible', 'off');
set(handles.logistic, 'Visible', 'on');
set(handles.cooling, 'Visible', 'off');
elseif strcmp (popupmenu1,'Newtons Law of Cooling')
set(handles.second, 'Visible', 'off');
set(handles.mixture, 'Visible', 'off');
set(handles.logistic, 'Visible', 'off');
set(handles.cooling, 'Visible', 'on');
end

댓글 수: 2

Cris LaPierre
Cris LaPierre 2019년 1월 5일
should i upgrade to 2018 version?
You need to measure the impact that may have on your workflow, but 9 times out of 10, the answer is yes. There are so many new features you are missing out on!
Ma.Cathyrine Ravina
Ma.Cathyrine Ravina 2019년 1월 5일
Okay :) I can still copy the codes i have on my previous work, right? :)

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

 채택된 답변

Cris LaPierre
Cris LaPierre 2019년 1월 5일
편집: Cris LaPierre 2019년 1월 5일

0 개 추천

Your code logic looks good. The issue, I think, is that you are indexing incorrectly into contents to assign a value to popupmenu1. Your code is
contents(get(hObject,'Value'))
but the code Guide provides in the callback hint is
contents{get(hObject,'Value')}
Note the use of curly braces {}

댓글 수: 2

I was testing in 15a so thought I'd share what my callback for the popupmenu looks like.
% --- Executes on selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu1
contents = cellstr(get(hObject,'String'))
switch contents{get(hObject,'Value')}
case 'Panel1'
handles.uipanel1.Visible = 'on';
handles.uipanel2.Visible = 'off';
handles.uipanel3.Visible = 'off';
case 'Panel2'
handles.uipanel2.Visible = 'on';
handles.uipanel1.Visible = 'off';
handles.uipanel3.Visible = 'off';
case 'Panel3'
handles.uipanel3.Visible = 'on';
handles.uipanel1.Visible = 'off';
handles.uipanel2.Visible = 'off';
end
Ma.Cathyrine Ravina
Ma.Cathyrine Ravina 2019년 1월 6일
Wonderful!! It works :)))) thank you so much :)

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by