Create a Slider-Crank Animation with MATLAB | Learn MATLAB Through Projects
In this tutorial you are going to learn how to display a slider crank animation using MATLAB plot,and save it as a video.
In this video I talk about:
- How to use plot command in MATLAB effectively.
- How to save every frame of a figure to a video file.
- How to use a for loop to create multiple frames and plots.
- How to use pause function to give a sense of passage of time.
- what is a video object, how to write the frames into it and how to modify it.
- the fill command
💢💢💢💢💢💢
This video is the first part of "Learning MATLAB through Projects". If you think it is a good idea to illustrate how to use MATLAB in real-life examples and projects, let me know in the comments.
💢💢💢💢💢💢
* Important * Attention *
🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻
If you want the code of this program, leave your E-mail in the comments and I will send you the M-file.
🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺
If you enjoyed this tutorial, please consider hitting the SUBSCRIBE button. Or click on the link below:
bit.ly/3q1he3v
So:
If you want to learn MATLAB:
bit.ly/3q1he3v
Here's the full MATLAB for beginners playlist:
• Beginner's Guide to MA...
You can also follow us on
Instagram:
/ laplaceacademy
Facebook:
/ laplaceacademy
LinkedIn:
/ laplaceacademy
Twitter:
/ laplace_academy
0:00 - Introduction
01:42 - Plotting the Slider-Crank
03:40 - Fill command in MATLAB
05:16 - Save animation as a video in MATLAB
#laplaceacademy #matlabproject
Пікірлер: 18
Nice 👏
@LaplaceAcademy
2 жыл бұрын
Thanks ❤❤
Hello what if I wanted to do it vertical with the crank on the bottom. I have tried but it turns out the the crank move downwards whilst point A goes up. Thank you anyway.
how different would the code be for an inverted slider crank?
👍
@LaplaceAcademy
2 жыл бұрын
❤️❤️
You genius. My Jesus I love you
@LaplaceAcademy
Жыл бұрын
I'm absolutely flattered by your comment. I'm glad you like it. ❤️
nice
@LaplaceAcademy
2 жыл бұрын
Tnx. I'm glad it was helpfu;
Thanks for the video but it is e-c/2 would appreciate it if you could correct it line 7 2:13
@LaplaceAcademy
2 ай бұрын
Thank you for your interest in this code. Actually it depends on your definition of 'e'. I took 'e' as the vertical distance between O and the sliding surface. So in this definition my code is definitely correct. You can define 'e' in another way and change the code accordingly.
thanks alot can you share your code because i am having a error much appreciate if you share your code 👍
@LaplaceAcademy
Жыл бұрын
close all; clear all; clc; r = 1; n = 100; theta = linspace(0, 2*pi, n); Ax = r * cos(theta); Ay = r * sin(theta); a = 2.5; e = 0.25; c = 0.5; d = 1; t = 0.06; By = e + c/2; Bx = Ax + sqrt(a^2 - (Ay - e - c/2).^2); axislimits = [min(Ax)*1.1 max(Bx)*1.2 min(Ay)*1.1 max(Ay)*1.1]; sliderY = [e e+c e+c e e]; groundX = [min(Bx)-d/2 min(Bx)-d/2 max(Bx)+d/2 max(Bx)+d/2 min(Bx)-d/2]; groundY = [e-t e e e-t e-t]; videoObject = VideoWriter('slider crank', 'MPEG-4'); videoObject.FrameRate = 15; open(videoObject) for ii = 1:n plot(Ax, Ay, '--', 0 ,0, 'ko') axis equal hold on sliderX = [Bx(ii)-d/2 Bx(ii)-d/2 Bx(ii)+d/2 Bx(ii)+d/2 Bx(ii)-d/2]; fill(sliderX, sliderY, 'm') fill(groundX, groundY, 'g') plot([0, Ax(ii)], [0, Ay(ii)], 'k', 'linewidth', 2) plot(Ax(ii), Ay(ii), 'ko') plot(Bx(ii), By,'ko') axis(axislimits) plot([Ax(ii), Bx(ii)], [Ay(ii), By], 'k', 'linewidth', 2) axis off hold off frames(ii) = getframe; end for kk = 1:5 writeVideo(videoObject, frames) end close(videoObject)
@LaplaceAcademy
Жыл бұрын
Hi. I hope it helps you. I couldn't find your email address, so I just pasted the code right here. If you needed more help, contact me via laplaceacademy1@gmail.com
@twinsz3498
Жыл бұрын
@@LaplaceAcademy Thanks alot
Can you share the complete source code?
@LaplaceAcademy
2 ай бұрын
Yes. Please send an email to laplaceacademy1@gmail.com