MATLAB - how to use event.eventData, and efficiently

For background information and context for my question, please read this question.

Notice in the updatePlot() method of my DynamicPlotter code, I kind of "reach into" a DynamicDataset property, as follows:

function updatePlot(obj, propNum)
    X = get(obj.LH(propNum), 'XData');
    Y = get(obj.LH(propNum), 'YData');

    X(end+1) = obj.(dynProps{propNum}).newestData(1);
    Y(end+1) = obj.(dynProps{propNum}).newestData(2);

    set(obj.LH(propNum), 'XData', X, 'YData', Y);

updatePlot is a listener callback. Rather than "reach in" to go get the newestData, I am wondering if it would be more efficient to have the data "presented" to the callback with event.eventData. But I am unsure of (a) how to even use event.eventData (the example provided in the documentation isn't very clear to me), and (b) if this yields better or worse performance.

So I guess my main question is, what's the best way for updatePlot() to access the newestData as depicted in the method above: "reaching in and retrieving it" or using event.eventData to "send" the data point to the function to plot?

I hope this wasn't terribly ambiguous.


You first need to have a class that defines an event (in MyClass.m):

classdef MyClass < handle
    % Event

    function obj = MyClass
      % Constructor

Then you need to create your own EventData subclass (in MyEventData.m):

classdef MyEventData < event.EventData
  properties (Access = public)
    % Event data

    function this = MyEventData(data)
      % Constructor
      this.Data = data;

Attach your data to an instance of the event data class (in a script file):

X = 1:10;
Y = 1:10;
data = struct('XData', X, 'YData', Y);
eventData = MyEventData(data);

And fire the event from your obj and have a listener listen to it:

obj = MyClass;
l = addlistener(obj, 'MyEvent', @(evtSrc,evtData)disp(evtData.Data));
notify(obj, 'MyEvent', eventData)

Anytime you call notify(...), the evtData argument in your listener callback will have your data in its Data property:

>> notify(obj, 'MyEvent', eventData)
    XData: [1 2 3 4 5 6 7 8 9 10]
    YData: [1 2 3 4 5 6 7 8 9 10]

Need Your Help

What to use Flush Mode 'Auto' or 'Commit'

java spring hibernate session

As my title described right now in my application I am using hibernate Auto flush mode mechanism that is why when I am changing any data in hibernate persistent object it reflects automatically in

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.