With a MATLAB Function block, you can write a MATLAB function for use in a Simulink model.
www.mathworks.com