Plotting position every 10 secound
이전 댓글 표시
I have this code that plots two objects moving around. I would like to add such that it marks the position of both objects for every 10-20 times it runs through. How Do I do that?
axis([-0,400,-200,200])
hold on
% Data
x1 = squeeze(x_V);
y1 = squeeze(y_V);
N1 = NaN(size(x1));
x2 = squeeze(x_O);
y2 = squeeze(y_O);
N2 = NaN(size(x2));
% Create the line and get its X and Y data
h1 = plot(N1, N1);
h2 = plot(N2, N2);
xdata1 = get(h1, 'XData');
ydata1 = get(h1, 'YData');
xdata2 = get(h2, 'XData');
ydata2 = get(h2, 'YData');
for k = 1:length(x1)
xdata1(k) = x1(k);
ydata1(k) = y1(k);
xdata2(k) = x2(k);
ydata2(k) = y2(k);
% Update the plot
set(h1, 'XData', xdata1, 'YData', ydata1, 'Color', 'red');
set(h2, 'XData', xdata2, 'YData', ydata2, 'Color', 'blue');
drawnow
end
채택된 답변
추가 답변 (1개)
Image Analyst
2015년 3월 23일
0 개 추천
Try rem() or mod(). Like "if rem(k, 10)" inside the loop to plot only every 10th time.
댓글 수: 3
Mikkel
2015년 3월 23일
Image Analyst
2015년 3월 23일
Did you use "hold on"? If you want lines between the markers, use 'ro-'. You can adjust the line width with the 'LineWidth' option of plot().
Mikkel
2015년 3월 24일
카테고리
도움말 센터 및 File Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!