필터 지우기
필터 지우기

callback problem for a GUI

조회 수: 1 (최근 30일)
Mohammed Alruwaili
Mohammed Alruwaili 2017년 11월 8일
답변: Brendan Gray 2017년 11월 8일
Hello I have a GUI which allows the user to enter two deferent parameters and inside the GUI I call back another m file that contains the functions. I would like to make my m file use the two entered parameters from GUI. Thanks
  댓글 수: 1
Chandrasekhar
Chandrasekhar 2017년 11월 8일
have you tried creating a function with the entered parameters and calling from GUI

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

답변 (1개)

Brendan Gray
Brendan Gray 2017년 11월 8일
The best way to do this depends on whether you are building the GUI using App Designer, GUIDE or building it programmatically. However, what may solve your problem is using a cell array to set the callback function. The first element is the function handle for the callback, and any other elements in the cell array are passed as extra arguments to the callback. For example, your callback could look something like this:
function [outputArg1,outputArg2] = callbackFcn(source, ~, param1value, param2value)
% Do something with the parameters
disp(param1value);
disp(param2value);
end
And then the code in the GUI that sets the callback would look something like this
% Create a simple GUI
figure();
edt1 = uicontrol('Style', 'edit', 'String', 'Enter parameter 1', ...
'Units', 'normalized', 'Position', [0.2, 0.7, 0.6, 0.2]);
edt2 = uicontrol('Style', 'edit', 'String', 'Enter parameter 2', ...
'Units', 'normalized', 'Position', [0.2, 0.4, 0.6, 0.2]);
btn = uicontrol('Style', 'pushbutton', 'String', 'Press this', ...
'Units', 'normalized', 'Position', [0.2, 0.1, 0.6, 0.2]);
% Set the callback using a cell array and pass the contents of the
% edit boxes as additional arguments
btn.Callback = {@callbackFcn, edt1.String, edt2.String};

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by