model='untitled';
timeout=10;
set_param(model,'SimulationCommand','start')
tic;
while(true)
if not(strcmpi(get_param(model,'SimulationStatus'),'running'))
disp('simulation exited')
break;
end
if toc>=timeout
disp('timout reached')
set_param(model,'SimulationCommand','stop')
break;
end
pause(1);
end
1 回答
通常在(加速)模拟中使用真实世界时钟并不是一个好主意 . 这是一个使用m脚本设置超时的简单示例 . 它主要基于this documentation page
如果您不喜欢轮询,也可以使用callbacks实现,但这需要在模型中插入回调 .