I want to move an object along Y axis up and down. how can I do this? Thanks in advance.
12 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Max Heimann
on 2 Feb 2022
Edited: Max Heimann
on 2 Feb 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 Comments
See Also
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!