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

12 ビュー (過去 30 日間)
JIBIN GEORGE
JIBIN GEORGE 2022 年 2 月 2 日
編集済み: Max Heimann 2022 年 2 月 2 日
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 Center および File ExchangeAnnotations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by