Callback function not found for dynamically created app UI component
Show older comments
I would like to dynamically/programmtically create a uidropdown component that calls a function when its value is changed. However, even though I provide a function handle as the ValueChangedFcn property, the uidropdown is unable to find the function. I receive the error below.
Undefined function 'DropDownChange' for input arguments of type 'matlab.ui.control.DropDown'.
Error using matlab.ui.control.internal.controller.ComponentController/executeUserCallback (line 305)
Error while evaluating DropDown PrivateValueChangedFcn
I am attaching a simple app created in R2016b that exhibits this behavior. Why can't the function be found? How should I define it to resolve the issue?

2 Comments
Jan
on 20 Mar 2021
Please post code as text, such that writing an answer allows to copy&paste.
Monika Jaskolka
on 20 Mar 2021
Edited: Monika Jaskolka
on 20 Mar 2021
Accepted Answer
More Answers (2)
As far as I can see, Matlab searchs for a matching function with the input (app, event), but your callback accepts (app) only. So try to append a 2nd (unused...) input to your CropDownChange function.
[EDITED] No, this does not work.
1 Comment
Monika Jaskolka
on 20 Mar 2021
Edited: Monika Jaskolka
on 20 Mar 2021
Bear
on 15 Nov 2021
I have a similar issue.
I'm creating a submenu voice with a file path and I want to associate a function. The idea is the add a voice every time the user selects a directory in order to have a history of selected folders.
I would like to catch also the event when the user selects a folder in order to retrieve the selected path and move to that folder.
mitem = uimenu(app.RecentpathsMenu,"Text",user_dir,"MenuSelectedFcn",@(~,~)app.ChangePath);

Categories
Find more on Develop Apps Using App Designer 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!