第一步:使用open_system打开simulink工程,如下:
open_system('xxx.slx');
第二步:使用set_param,启动simulink,如下:
set_param(bdroot,'SimulationCommand','start');
注意这里的bdroot指的是从打开的simulink顶层开始。
第三步:使用get_param,确认simulink是否执行完成:
while(get_param(bdroot,'SimulationStatus')=='running')
pause(1);
end
一个案例:
clc; clear all; close all;
open_system('xxx.slx');
% 用户初始化代码段
nn=100;
for i=1:nn
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 用户对xxx.slx内部参数进行配置
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
set_param(bdroot,'SimulationCommand','start');
while(get_param(bdroot,'SimulationStatus')=='running')
pause(1);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 对xxx.slx执行完以后进行处理
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end