clear plot and add a new plot to the current figure

조회 수: 11 (최근 30일)
negin tebyani
negin tebyani 2018년 2월 27일
댓글: KL 2018년 3월 1일
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
negin tebyani
negin tebyani 2018년 2월 27일
when I use clf, it clears the whole plot
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