フィルターのクリア

How can I animate springs in MATLAB?

5 ビュー (過去 30 日間)
Srikar V.S
Srikar V.S 2023 年 3 月 29 日
回答済み: Star Strider 2023 年 3 月 29 日
I'm trying to animate a simple spring-mass system vibrating freely. I managed to animate a block vibrating according to the response of a free vibration using the method of continuos plots using a for loop. Now, i want to include the spring in the system so as to complete the movie. However, I'm having a hard time trying to do that, I'm a beginner in MATLAB, so I don't know much about the various functions available in it. I couldn't get the right source to help me out.

採用された回答

Star Strider
Star Strider 2023 年 3 月 29 日
One approach —
L = 1600; % Vector Lengths
t = linspace(0, 16*pi-(1/L), L); % Eight Cycles
r = 1; % Radius
x = r*cos(t); % X-Coordinate
y = r*sin(t); % Y-Coordinate
tz = linspace(0, t(end), fix(L/2)); % Length Governs Frequency Of Oscillation
zv = (1+sin(tz))*4; % Oscillation
figure
for k = 1:numel(z)
z = linspace(0, zv(k), L)+2; % Define Spring Length For This Cycle
plot3(x, y, z, 'LineWidth',2.5) % Draw Spring
axis([-1.5 1.5 -1.5 1.5 0 10]) % Fix Axis Limits
grid on % Draw Grid
drawnow % Animate
end
It does not show the animation here, however it does work.
Experiment with it to get the result you want. (I did my best to document it in the comments.) In the loop, the ‘z’ value controls the length for each iteration, using the ‘zv’ value, however ‘zv’ can be anything. It does not have to be the vector I used here to test the code, so in reality it will be related to something in your animation. I have drawn it vertically here, however by changing the order of the plot3 call arguments, you can put it in different orientations. You can also use the rotate function to put it in other orientations, if necessary.
.

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by