This m-script shows a simple simulation for the crank-slider mechanism of the piston.
how to get this piston to slide horizontally?
The code is simple, neat, and clean. It's not quite made to be customized, but does exactly what it says it will do.
Why not make this a function so it's easier for the user to alter the arguments? Maybe space out the code and add some comments. Clear the figure at the beginning with clf.
Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.