Are you able to do this on CFTOOL? if you are then you can go to File > Generate Code
This will automatically generate the MATLAB code for you.
If you want to do this yourself then you can follow the steps in the doc here:
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!