execute fcn by a change of a Property

2 views (last 30 days)
Hey Guys, Imagine I would have 1000 Buttons, which calculate some Data and then put the Solution into a Listbox. Everytime I hit a Button the Listbox is filled. Now I need a Code, that excutes everytime the Listbox gets filled and checks wheter there are Elements twice. I have no idea how to do that: Callbacks are now solution i guess....

Accepted Answer

Sean de Wolski
Sean de Wolski on 24 Sep 2014
Though Adam's approach is ideal, you could skip it and just add a listener to the 'PostSet' event of the ListBox' 'String'. Then it will fire whenever that string changes. You can add these listeners to any property that you need to observe.
doc addlistener
To get started.
  1 Comment
Max Müller
Max Müller on 25 Sep 2014
wrote a Controll fcn which and included it into every Button...

Sign in to comment.

More Answers (1)

Adam
Adam on 24 Sep 2014
Personally I would use a class to represent your data and add a listener to that class, but that would require you to read up about object-oriented programming in Matlab.
Working purely with things attached to the handles structure under a GUI is ok to a certain extent, but when your program starts to get complicated you ideally need some better underlying data structures to manage your data. This also has the advantage of being decoupled from your UI so that you could also run the core of your program from a command-line instruction for example.
Linking your functionality too strongly to the concept of pressing buttons on a UI can make it difficult to extend and use in different settings if the need arises. Programming it based on the actions that are performed (e.g. a function call on a class object to set some data which can in turn notify listeners that a change has been made) gives greater flexibility that you can then attach a lightweight UI to, whether that be buttons or some other methods of triggering the functionality.
provides good documentation on classes and using listeners with them if you wish to go down that route.

Categories

Find more on Migrate GUIDE Apps 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!