To use pidtune function in MATLAB, follow the steps below:
pidtune object using the system to tune, desired response type, and other options:main.m179 chars4 lines
step command:main.m43 chars3 lines
pidtune function:main.m35 chars2 lines
This will calculate the appropriate gains and returns the closed loop system and performance information.
main.m78 chars4 lines
This will create the closed-loop system around the plant sys  , using the optimized PID controllers C, and produce the step response of the system.
Note that there are many other techniques and options available in pidtune function to design PID controllers in MATLAB.
References:
pidtune: https://www.mathworks.com/help/control/ref/pidtune.htmlgistlibby LogSnag