Check out this link: http://www.mathworks.com/help/simulink/ug/functions-supported-for-code-generation--categorical-list.html#buimyq3
which generates a function that you can use with MATLAB Coder.
Hope that helps,
-Adam
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!