Contenu principal

Programming Constructs in Simulink

Simulink command – MATLAB® command that is specific to Simulink®modeling or simulation. Enter Simulink commands in the MATLAB Command Window or use in MATLAB scripts for testing a model programmatically. The following commands set simulation parameters, run a simulation, and saves the simulation results. In the first statement, sim is a Simulink command for running a simulation.

simOut = sim('cruise_control','SimulationMode','normal',...
             'AbsTol','1e-5','SaveState','on',...
             'StateSaveName','xout','SaveOutput','on',...
             'OutputSaveName','yout','SaveFormat', 'Dataset');
outputs = simOut.get('yout')

callback, model callback – MATLAB code that executes in response to a specific model or block action. To add a model callback, in the Modeling tab, under Design, click Property Inspector, then in the Properties tab, select a function from the Callbacks list, and then enter MATLAB code or the name of a MATLAB script.

In the following example, when Simulink loads a model it also loads a file into the MATLAB workspace with parameters values for the model.

Simulink function – Computational unit that calculates a set of outputs when provided with a set of inputs. A common text interface between function caller and function definition allows various definition formats using a Simulink Function block, exported Stateflow graphical function, or exported Stateflow MATLAB function.

MATLAB Function

S-function, system-function – Computer language description of a Simulink S-Function block written in MATLAB code, C, C++, or Fortran. C, C++, and Fortran S-functions are compiled as MEX files using the MATLAB mex utility.