Passing Variables from GUI to Script
2 views (last 30 days)
Show older comments
junkbond916
on 13 Oct 2017
Answered: Rajesh Balagam
on 16 Oct 2017
Hello All. I have built an analysis tool that boots up to a UI with dropdown menus. The 'Run PME Analysis' button runs a script with a SQL query that is generated from values in the dropdowns ("run_pme").
But, I have been unable to pass variables from the GUI dropdowns to my script. Here is the code from the top dropdown and the first bit of code from the script:
if true
function popfirm_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
firmcontents = cellstr(get(hObject,'String'));
firm = firmcontents{get(hObject,'Value')};
if (strcmp(firm,'All Firms'))
firmquery = '';
else
firmquery = strcat('AND [Firm] ='," '", firm, "'");
end
handles.firmquery = 'firmquery';
guidata(hObject, handles);
if true
function popfirm_Callback(hObject, eventdata, handles)
firmcontents = cellstr(get(hObject,'String'));
firm = firmcontents{get(hObject,'Value')};
if (strcmp(firm,'All Firms'))
firmquery = '';
else
firmquery = strcat('AND [Firm] ='," '", firm, "'");
end
handles.firmquery = 'firmquery';
guidata(hObject, handles);
end
if true
function run_pme(obj, eventData, handles)
firmq = handles.firmquery
end
When I click the "Run PME" Button, I get the following error:
_Not enough input arguments.
Error in PME_Analysis_Full>run_pme (line 206) firmq = handles.firmquery_
I'm sure the problem will be obvious to anyone with experience but I'm still quite new. Any help you can provide would be most appreciated.
Thanks!
2 Comments
Adam
on 13 Oct 2017
How is run_pme called? Is it the callback for the button that you renamed to not include the usual 'callback' part of its name?
Accepted Answer
Rajesh Balagam
on 16 Oct 2017
Refer to the following MATLAB documentation page for some pointers on sharing the data among UI elements.
It seems the error observed in your code is due to calling run_pme function with no input arguments whereas the run_pme function expects 3 inputs.
0 Comments
More Answers (0)
See Also
Categories
Find more on Environment and Settings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!