Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 18th, 2012  |  syntax: None  |  size: 1.00 KB  |  hits: 18  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. MATLAB - how to use event.eventData, and efficiently
  2. function updatePlot(obj, propNum)
  3.     X = get(obj.LH(propNum), 'XData');
  4.     Y = get(obj.LH(propNum), 'YData');
  5.  
  6.     X(end+1) = obj.(dynProps{propNum}).newestData(1);
  7.     Y(end+1) = obj.(dynProps{propNum}).newestData(2);
  8.  
  9.     set(obj.LH(propNum), 'XData', X, 'YData', Y);
  10. end
  11.        
  12. classdef MyClass < handle
  13.   events
  14.     % Event
  15.     MyEvent
  16.   end
  17.  
  18.   methods
  19.     function obj = MyClass
  20.       % Constructor
  21.     end
  22.   end
  23. end
  24.        
  25. classdef MyEventData < event.EventData
  26.   properties (Access = public)
  27.     % Event data
  28.     Data
  29.   end
  30.  
  31.   methods
  32.     function this = MyEventData(data)
  33.       % Constructor
  34.       this.Data = data;
  35.     end
  36.   end
  37. end
  38.        
  39. X = 1:10;
  40. Y = 1:10;
  41. data = struct('XData', X, 'YData', Y);
  42. eventData = MyEventData(data);
  43.        
  44. obj = MyClass;
  45. l = addlistener(obj, 'MyEvent', @(evtSrc,evtData)disp(evtData.Data));
  46. notify(obj, 'MyEvent', eventData)
  47.        
  48. >> notify(obj, 'MyEvent', eventData)
  49.     XData: [1 2 3 4 5 6 7 8 9 10]
  50.     YData: [1 2 3 4 5 6 7 8 9 10]