I want to move an object along Y axis up and down. how can I do this? Thanks in advance.
12 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
made this using function
Obs5 = [125 0];
obst(125,0,5,1)
function obst(x,y,r,n)
theta= linspace(0, 2*pi,n);
x1= x+r*cos(theta);
y1= y+r*sin(theta);
plot(x,y,'o','markerfacecolor','g','markersize',6),hold on
plot(x1,y1,'r-')
axis equal
end
0 commentaires
Réponses (1)
Max Heimann
le 2 Fév 2022
Modifié(e) : Max Heimann
le 2 Fév 2022
Do you just want to offset the data once or do you want to move it after you already plotted it?
For offsetting just once, just add the offset to your y vector.
plot(x1,y1 + offset,'r-')
If you want to move an existing line you can store the handle when you plot it the first time and then modifiy it with the set command.
% plot and store handle
handleOfLine = plot(x1,y1,'r-');
% change data
set(handleOfLine,'YData',y1 + offset);
% refresh the figure
drawnow
Place this into a loop and add a pause() call somewhere and you can create a moving plot.
0 commentaires
Voir également
Catégories
En savoir plus sur Annotations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!