Code generation has many purposes and methods. There are two essential rationales:
Compiled code versions of Simulink® and Simscape™ models run faster than the original block diagram models. The time savings can be dramatic.
An equally important consideration for Simscape models is the standalone implementation of generated and compiled code. Once you convert part or all of your model to code, you can deploy the standalone executable program on virtually any platform, independently of MATLAB®.
Converting a model or subsystem to code also hides the original model or subsystem.