Plotting position every 10 secound
Mostra commenti meno recenti
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
Risposta accettata
Più risposte (1)
Image Analyst
il 23 Mar 2015
0 voti
Try rem() or mod(). Like "if rem(k, 10)" inside the loop to plot only every 10th time.
3 Commenti
Mikkel
il 23 Mar 2015
Image Analyst
il 23 Mar 2015
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
il 24 Mar 2015
Categorie
Scopri di più su Creating, Deleting, and Querying Graphics Objects in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!