The key to calling the model mdl in the m file is to use the sim command.
[ t, x, y ] = sim( model, timespan, options, ut)
[ t, x, y1, y2, …, yn] = sim( model, timespan, options, ut)
(1) model: the name of the block diagram of the system model to be simulated;
(2) timespan: The time range of the system simulation (start to end time), which can have the following forms:
tFinal:设置仿真终止时间。仿真起始时间默认为0;
[tStarttFinal]:设置起始时间(tStart)与终止时间(tFinal);
[tStartOutputTimestFinal]:设置起始时间(tStart)与终止时间(tFinal),并且设置仿真返回的时间向量[tStartOutputTimestFinal],其中tStart、 OutputTimes、tFinal必须按照升序排列。
(3) options: simulation parameters other than simulation time set by the simset command;
(4) ut: represents an external optional input at the top level of the system model. ut can be a MATLAB function. Multiple external inputs ut1, ut2, … can be used.
(5) t: Returns the time vector of the system simulation.
(6) x: Returns the state variable matrix of the system simulation.
(7) y: Returns the output matrix of the system simulation. Output in the order in which the top-level output Outport blocks are output. If the output signal is a vector output, the output signal has the same dimension as this vector.
(8) y1,...,yn: Returns the output of multiple system simulations.
改变模型输入参数的demo,同时不影响原来的mdl文件
>t=0:0.1:10; t=t’; u=sin(t); sim_input=[t, u];
>[tout1, x1, yout1]=sim(‘command_in_out’, 10); %使用Simulink仿真参数对话框中的workspace I/O 从MATLAB 工作空间中获得输入信号
>u=cos(t);
>ut=[t, u]; %改变系统输入信号
>>[tout2, x2, yout2]=sim(‘command_in_out’, 10, [], ut);