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

조회 수: 28 (최근 30일)
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

답변 (1개)

Max Heimann
Max Heimann 2022년 2월 2일
편집: Max Heimann 2022년 2월 2일
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.

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by