フィルターのクリア

How to create a time function and make a line rotate at a certain angular speed?

3 ビュー (過去 30 日間)
Brent
Brent 2023 年 5 月 26 日
回答済み: Alan Stevens 2023 年 5 月 26 日
Hello! I have a question regarding my code I am trying to make an animation of a four bar linkage but in the end I need to plot theta_2 vs time. Angular speed should be 1 rad/sec, but I'm having trouble trying to wrap my head around the concept of time in MATLAB. How could I make the line rotate at a certain angular speed and how would I plot a graph of theta vs time? Any insight would be appreciated! Thanks!
r2_length = 2;
theta_2 = 0:0.1:2*pi;
y_r2 = r2_length * sin(theta_2);
x_r2 = r2_length * cos(theta_2);
origin = [0,0];
for i = 1:length(theta_2)
r2 = line([origin(1) x_r2(i)], [origin(2) y_r2(i)],'linewidth', 2);
hold on
axis([-10 10, -10 10]);
grid on
pause(0.001);
if i ~= length(theta_2)
clf
end
end

回答 (1 件)

Alan Stevens
Alan Stevens 2023 年 5 月 26 日
Do you mean something like this?
r2_length = 2;
tend = 10; % s
dt = 0.1;
t = 0:dt:tend;
omega = 1; % rad/s
theta = omega*t;
y_r2 = r2_length * sin(theta);
x_r2 = r2_length * cos(theta);
origin = [0,0];
for i = 1:length(theta)
r2 = line([origin(1) x_r2(i)], [origin(2) y_r2(i)],'linewidth', 2);
hold on
axis([-5 5, -5 5]);
grid on
pause(0.001);
if i ~= length(theta)
clf
end
end

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by