execute fcn by a change of a Property

조회 수: 4 (최근 30일)
Max Müller
Max Müller 2014년 9월 24일
댓글: Max Müller 2014년 9월 25일
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....

채택된 답변

Sean de Wolski
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
Max Müller
Max Müller 2014년 9월 25일
wrote a Controll fcn which and included it into every Button...

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

추가 답변 (1개)

Adam
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.

카테고리

Help CenterFile Exchange에서 App Building에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by