Plot points with unknown column numbers

조회 수: 2 (최근 30일)
Avni
Avni 2012년 6월 5일
Hello
I am trying to plot points with unknown column numbers for instance: plot (fx,fy,'bo',ax(i,1),ay(i,1),'bo',ax(i,2),ay(i,2),'bo')
where fx and fy are not changing, however ay and ax will plot according the row and column number all on the same time. However, every time I will be getting n columns ranging from 1 to depends. I tried hold on but the points from the previous plot are there, in which i dont want.
is there a way that i can automate this code to generate a line as the code above with different column numbers every time ?
here is the full code figure(2) names = 1:1:rx; for i =1:1:rx name = i; plot (fx,fy,'bo',ax(i,1),ay(i,1),'bo',ax(i,2),ay(i,2),'bo') xlim([0 50]); ylim([0 50]); title(sprintf('%s Step: %i',sys,i)); pause (0.5) end
Thanks

채택된 답변

Kevin Holst
Kevin Holst 2012년 6월 5일
Here's the fix, sorry it took a while. Got distracted ;)
figure(2)
names = 1:1:rx;
for i =1:1:rx
name = i;
plot (fx,fy,'bo')
xlim([0 50]);
ylim([0 50]);
hold on
for j = 1:scell
plot(ax(i,j),ay(i,j),'bo')
end
title(sprintf('%s Step: %i',sys,i));
pause (0.35)
hold off
end

추가 답변 (2개)

Kevin Holst
Kevin Holst 2012년 6월 5일
did you turn hold back off?
figure(2)
names = 1:1:rx;
for i =1:1:rx
name = i;
plot (fx,fy,'bo')
xlim([0 50]);
ylim([0 50]);
hold on
for j = 1:size(ax,2)
plot(ax(i,j),ay(i,j),'bo')
title(sprintf('%s Step: %i',sys,i));
pause (0.5)
end
hold off
end
  댓글 수: 3
Kevin Holst
Kevin Holst 2012년 6월 5일
Let me see if I have this correct... you have 2 vectors fx,fy that are not changing and they should be there at all times. Then you have two matrices ax, ay where the rows are different cases (presumably) and the columns are different timesteps? So the first plot should be fx,fy and one point at ax(1,1),ay(1,1). The plot should then wait 0.5 seconds and then plot the second point on the axes at ax(1,2),ay(1,2), along with the first point and fx,fy. Is that right? If that's the case, then I think I've updated the code to do that... also your title should probably change with every column step right? if that's the case, then you'll need to change the i in your tltle call to a j.
Avni
Avni 2012년 6월 5일
not quite, i emailed you the code along with the data, so it may be easier to understand the difference between my plot code and yours!

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


Avni
Avni 2012년 6월 5일
sorry the code came out funky
figure(2)
names = 1:1:rx;
for i =1:1:rx
name = i;
plot (fx,fy,'bo',ax(i,1),ay(i,1),'bo',ax(i,2),ay(i,2),'bo')
xlim([0 50]);
ylim([0 50]);
title(sprintf('%s Step: %i',sys,i));
pause (0.35)
end

카테고리

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