Draw utilizing GUI handles

1 次查看(过去 30 天)
Samer
Samer 2012-7-28
I have developed a code for drawing dynamically changing neighbor nodes to a moving one. The problem is that when I draw them, and they get changed, it adds the new nodes (yellow color) to the old ones and does not clean the old drawn ones. I am using drawnow and plot and tried lots of variations.
I would much appreciate any help on this. The code is below:
valAnchors=get(handles.hshowAnchors,'Value');
if valAnchors
%hold on;
for j=1:numel(T_R_neighbour(:,1))
node=T_R_neighbour(j,1);
n_X=net(2,node);
n_Y=net(3,node);
sendPointAnch(j) = line('XData',1, 'YData',1, 'EraseMode','normal', ...
'Color','y', 'Marker','.', 'MarkerSize',30);
set(sendPointAnch(j), 'XData',n_X, 'YData',n_Y) %# update point location
end
end

回答(1 个)

Walter Roberson
Walter Roberson 2012-7-28
MATLAB has some graphic primitives that always always add to the current scene, without erasing anything that is already there. These primitives include line(), patch(), image(), and a few others. (However, plot() is not one of the primitives.)
If you want to erase a graphics object created by a graphics primitive, then delete() it, or cla() to clear the axes.
Instead of creating new lines, you should consider using set() to change the position or color or other attributes of existing lines.

类别

Help CenterFile Exchange 中查找有关 Graphics Performance 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by