MATLAB Answers

clear plot and add a new plot to the current figure

516 views (last 30 days)
negin tebyani
negin tebyani on 27 Feb 2018
Commented: KL on 1 Mar 2018
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?

  0 Comments

Sign in to comment.

Answers (1)

KL
KL on 27 Feb 2018
You probably want to use clf
f = figure(1)
plot something
clf(f)
plot something else

  2 Comments

KL
KL on 1 Mar 2018
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.

Sign in to comment.

Sign in to answer this question.

Tags