Effacer les filtres
Effacer les filtres

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

3 vues (au cours des 30 derniers jours)
Bolivar
Bolivar le 30 Août 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 commentaires
Bolivar
Bolivar le 5 Sep 2013
pretty good, Thanks!
Sven
Sven le 6 Sep 2013
No problem Bolivar, remember to hit "accept" if the question is answered.

Connectez-vous pour commenter.

Réponses (1)

Sven
Sven le 30 Août 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?

Catégories

En savoir plus sur Graphics Object Programming dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by