clear plot and add a new plot to the current figure

11 次查看(过去 30 天)
I have a plot that I am showing it in figure 1. and also an iteration of 10 times
RRHcoo_x=[-560,-280,0,280,560,-560,-280,0,280,560,-560,-280,0,280,560,-560,-280,0,280,560]
RRHcoo_y=[-520,-170,200,530,-520,-170,200,530,-520,-170,200,530,-520,-170,200,530,-520,-170,200,530]
hold on;
X_length=length(RRHcoo_x);
figure(1)
for nn=1:X_length
x=RRHcoo_x(nn);
y=RRHcoo_y(nn);
plot(x,y,'-mo',...
'LineWidth',2,...
'MarkerEdgeColor','k',...
'MarkerFaceColor',[.49 1 .63],...
'MarkerSize',7);
end
axis([-700 700 -700 700]);
I have some points that should stay fixed in the plot and in each iteration some points should change place. the points that I have indicated in the code above, should stay in their place, but the points in the code below, change place in each iteration:
a=-700;
b=700;
usercoo_x = a + (b-a).*rand(1,numberofusers);
usercoo_y = a + (b-a).*rand(1,numberofusers);
X_length=length(usercoo_x);
for nn=1:X_length
x=usercoo_x(nn);
y=usercoo_y(nn);
figure(1)
plot(x,y,'--ro','LineWidth',2,'MarkerSize',4);
end
axis([-700 700 -700 700]);
when I run this code, the new iteration points are added to the previous iteration points. what I need is to clear only the points of the second plot in figure 1, and the points on new iteration should be added instead. what should stay fixed, is the points in the first plot. how can I do this in matlab?

回答(1 个)

KL
KL 2018-2-27
You probably want to use clf
f = figure(1)
plot something
clf(f)
plot something else
  2 个评论
KL
KL 2018-3-1
Ah okay, I think I understand what you're trying to do here. You should probably store your iteration results in a matrix (column wise) and ignore/delete the columns you don't want and plot again the matrix.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by