- In event how did you call the function set.NumEvent ? I dont think there should be a dot
- In listener, it is throwing me an error of missing comma before num2str in display function
Listener doesnt display messages after changes through workspace
3 views (last 30 days)
Show older comments
Yuval Blutman on 10 Dec 2022
Hello, I tried to practice with event and listener objects.
As I practiced, I made two classes, one with an event and one with a listener function upon the event.
I noticed that the listener doesnt display messages if the event is trigerred through the workspace.
The event code:
classdef EventPractice < handle
properties (SetObservable = true)
NumEvent = 1
obj.NumEvent = value;
The listener code:
classdef ListenerPractice < handle
NumListener = 1
function obj = ListenerPractice(EventSrc)
obj.NumListener = EventSrc.NumEvent
disp(['The event Num has changed. The listener Num changes to the same num: 'num2str(EventSrc.NumEvent)])
EventExample = EventPractice;
ListenerExample = ListenerPractice(EventExample);
Change at the Workspace:
Change reaction at the ListenerExample variable:
Empty Command Window:
After this whole process, If the NumListener variable changed at the listener function 'ListenerReaction', why didnt the disp() function also go into action?
Thank you for reading,
Nikhil on 19 Dec 2022
As I have mentioned earlier , your NumChangedEvent is triggered only when the setNumEvent function is called ( which is the case when you call the function ).
When you change the value throught workspace, no event is triggered and hence no display.
Even if you try something like objName.NumEvent = 10 from command line, the display function won't work as no event is triggered.
It is triggered only if you do objName.setNumEvent(10) ( literally call the function).
The only thing I am not able to figure out is, when I change value from workspace , the value is changed only in event and not listener.
Hope this helps.
Find more on Tables 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!