필터 지우기
필터 지우기

Passing Variables from GUI to Script

조회 수: 2 (최근 30일)
junkbond916
junkbond916 2017년 10월 13일
답변: Rajesh Balagam 2017년 10월 16일
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
Adam
Adam 2017년 10월 13일
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?
junkbond916
junkbond916 2017년 10월 13일
Sorry - I should have included the code for the "Run PME Analysis" button. Here you go:
if true
function runpmebutton_Callback(hObject, eventdata, handles)
run_pme;
end

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

채택된 답변

Rajesh Balagam
Rajesh Balagam 2017년 10월 16일
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개)

카테고리

Help CenterFile Exchange에서 Get Started with Statistics and Machine Learning Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by