필터 지우기
필터 지우기

I want to give list of value in popup menu and use that in push button.

조회 수: 9 (최근 30일)
Here is my code.
function SEC_Callback(hObject, eventdata, handles)
handles = guidata(hObject); % Not sure if handles is up to date already
switch get(handles.SEC, 'value')
case 1
S.a=7;
S.b=20;
case 2
S.a=5;
S.b=30;
otherwise
end
set(handles.popupmenu, 'UserData', S);
function ANS_Callback(hObject, eventdata, handles)
S = get(handles.SEC, 'UserData');
a = S.a;
b = S.b;
c = a + b;
set(handles.AANS,'string',num2str(c));
I get error 'Dot indexing is not supported for variables of this type.'
Error in pop>ANS_Callback (line 113)
a = S.a;'
Please help me.
pop.PNG
  댓글 수: 7
Yash Vaid
Yash Vaid 2019년 1월 17일
Thank you very much sir for your continues support. But I excatly cant understand what should I do. Please either send the code and procedure with figure file or decribe in simple way because I am beginner in GUI. Again thank you sir but please help me to fix this problem.
Yash Vaid
Yash Vaid 2019년 1월 17일
When I change popup menu option it gives error
'SWITCH expression must be a scalar or a character vector.
switch domaintype '
and when I push answer buttton it gives error
'Reference to non-existent field 'a'.
a = handles.a; '

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

채택된 답변

Walter Roberson
Walter Roberson 2019년 1월 17일
Note that when you initialize the pop-up by loading the figure constructed in GUIDE (or by creating a uicontrol), that the default Value property is empty -- and even if the Value happened to be set to something else at the time you had saved the figure in GUIDE, then the Callback property associated withe the control is not run when the control is loaded or created.
Thus, at the beginning, even though 'first' might be showing, the action associated with clicking 'first' has not been run. Furthermore, when you click on a popup value that is already the one selected, the callback might not be run and you might have to select a different value and then click back on the original in order to have the value associated with the original be set.
Therefore you need to be careful about how you initialize the controls.
One approach is to have your OpenFcn callback for the GUI set() the Value property of the control, and then execute the callback associated with the control in order to have the sequence run as-if that value had been manually clicked.
If you take this approach, be careful about what you invoke. The callback property that GUIDE stores is not a direct reference to the function to be called: instead it has to retrieve the handles structure and pass that into the function. Historically that involved executing a character vector, but that was improved later, but you might have to fake the callback object to get it to work. More secure is to retrieve the handles structure yourself and call the function yourself.
  댓글 수: 2
Walter Roberson
Walter Roberson 2019년 1월 17일
function SEC_Callback(hObject, eventdata, handles)
listStrings = get(handles.SEC,'String');
idx = get(handles.SEC,'Value');
if ~isscalar(idx)
waitfor( warndlg('No SEC entry has been selected yet') );
return
end
domaintype = listStrings{idx};
switch domaintype
case 'first'
a=7;
b=20;
case 'second'
a=5;
b=30;
otherwise
waitfor( warndlg('Select first or second') );
return
end
handles.a = a;
handles.b = b;
guidata(hObject, handles);
function ANS_Callback(hObject, eventdata, handles)
set(handles.ANS,'UserData',0);
if ~isfield(handles, 'a')
waitfor( warndlg('You need to select SEC first') );
return
end
a = handles.a;
b = handles.b;
c = a + b;
set(handles.AANS,'string',num2str(c));
Yash Vaid
Yash Vaid 2019년 1월 17일
Respected Sir,
Thank you very much for your help.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by