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

조회 수: 1 (최근 30일)
Bolivar . 2013년 8월 30일
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)
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표시 이전 댓글 수: 1숨기기 이전 댓글 수: 1
Sven 2013년 9월 6일
No problem Bolivar, remember to hit "accept" if the question is answered.

댓글을 달려면 로그인하십시오.

### 답변 (1개)

Sven 2013년 8월 30일
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:
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.

댓글을 달려면 로그인하십시오.

### 카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

### Community Treasure Hunt

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

Start Hunting!