update objects' coordinate of the same plot !!!!!!!!!!!!!!!!!!!

2 visualizaciones (últimos 30 días)
Bolivar
Bolivar el 30 de Ag. de 2013
Hallo,
I am trying to plot the changing coordinate of two objects and i wasn't successful yet. So, i was wondering if someone can give me a help. To make it clear the situation look like this:
assume following two objects
classdef user1
properties(SetObservable=ture)
coordinate
end
end
classdef user2
properties(SetObservable=ture)
coordinate
end
end
classdef updateGraph
methods
function obj = updateGraph(array_obj)
addlistener(array_obj,'coordinate','PreSet',@(x,y)update(obj,src,evnt))
end
function update(obj,src,evnt)
plot(src.coordinate);
end
end
end
It doesn't work since for each call of update a new plot is been generated. How can I do to just update coordinate on the same graph?
Thanks
Bolivar
  2 comentarios
Bolivar
Bolivar el 5 de Sept. de 2013
pretty good, Thanks!
Sven
Sven el 6 de Sept. de 2013
No problem Bolivar, remember to hit "accept" if the question is answered.

Iniciar sesión para comentar.

Respuestas (1)

Sven
Sven el 30 de Ag. de 2013
Hi Bolivar,
Let's just go with one object first for simplicity:
Here's the contents of the user1 class:
classdef user1 < handle
properties(SetObservable=true)
coordinate
end
properties
coordinatePlotHandle
end
methods (Static = true)
function update(src,evnt)
obj = evnt.AffectedObject;
if isempty(obj.coordinatePlotHandle)
obj.coordinatePlotHandle = plot(obj.coordinate(:,1),obj.coordinate(:,2));
else
set(obj.coordinatePlotHandle, 'XData', obj.coordinate(:,1), 'YData', obj.coordinate(:,2))
end
end
end
end
Now you can make a user1 object:
U = user1
Now you can tell it what should happen after its coordinate is updated:
addlistener(U,'coordinate','PostSet',@user1.update);
Now you can update its coordinate(s).
U.coordinate = [1 1; 2 4]
U.coordinate = rand(5,2)
You'll notice that the first time its coordinate was set, the event was triggered and a plot was made, with the plot handle being retained and stored in U.coordinatePlotHandle. The next time the coordinate is set, that plot handle is simply updated.
Does that help answer your question?

Categorías

Más información sobre Graphics Object Programming en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by