execute fcn by a change of a Property
2 ビュー (過去 30 日間)
古いコメントを表示
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....
0 件のコメント
採用された回答
Sean de Wolski
2014 年 9 月 24 日
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 件)
Adam
2014 年 9 月 24 日
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.
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!