I want to give list of value in popup menu and use that in push button.
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Yash Vaid
il 16 Gen 2019
Commentato: Yash Vaid
il 17 Gen 2019
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.
7 Commenti
Risposta accettata
Walter Roberson
il 17 Gen 2019
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 Commenti
Walter Roberson
il 17 Gen 2019
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));
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Startup and Shutdown in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!