Can't get 'ValueChangedFcn' callback to work for 'uidatepicker '

조회 수: 1 (최근 30일)
Lior Embon
Lior Embon 2018년 4월 30일
답변: Abhipsa 2025년 1월 30일
Hi, I'm would like to have a date picker window on my main app window, and I'd like something to happen whenever the date is changed. The help file says I can call a function using the 'ValueChangedFcn' callback, but I can't get it to work. This is the relevant piece of code: methods (Access = private)
function test(app)
uialert(app.UIFigure, 'It works!', 'It works!', 'Icon','help');
end
end
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
uidatepicker(app.UIFigure, 'Position', [780 350 100 22], 'ValueChangedFcn', test(app))
I get this error message - Error using app1/test Too many output arguments.
Error in app1 (line 431) runStartupFcn(app, @startupFcn)
Any ideas?

답변 (1개)

Abhipsa
Abhipsa 2025년 1월 30일
Hi, I understand that you want to add a date picker to the main app window and trigger an action whenever the date is changed using “ValueChangedFcn” callback function.
This issue can be resolved by using a function handle for the callback instead of directly invoking the function in the “ValueChangedFcn”. Additionally, confirm that the callback function is designed to accept the necessary input arguments.
methods (Access = private)
function test(app, src, event)
uialert(app.UIFigure, 'It works!', 'It works!', 'Icon', 'info'); % I have changed 'help' to 'info' here
end
end
% You can use the below code in runStartupFcn
uidatepicker(app.UIFigure, ...
'Position', [100 100 150 22], ...
'ValueChangedFcn', @(src, event) test(app, src, event));
Moreover, "help" used for the value of "Icon" parameter might not be valid, if it is not created explicitly, you can also use an icon from the set of predefined icons provided by MATLAB.
You can also refer to the below documentations for more details:

카테고리

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