I want to move an object along Y axis up and down. how can I do this? Thanks in advance.

29 vues (au cours des 30 derniers jours)
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

Réponses (1)

Max Heimann
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.

Catégories

En savoir plus sur Graphics Performance dans Help Center et File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by