每次谓词是真实的保存完整的Simulink SIMSTATE定期或在模拟过程中

问题描述 投票:0回答:1

我试图找到一种方法Simulink的过程中产生的多个中间SIMSTATE对象SIM运行时,在预定的时刻,让模拟运行到其指定的停止时间。

该文件说,这是唯一可以保存完整的最终状态,但也许有办法吗?

matlab simulink
1个回答
2
投票

如果您需要运行在Simulink用户界面模型,那么你就需要编写自定义模块,将暂停该模型,保存SIMSTATE,然后重新启动模拟,在特定的时间间隔。但更简单的方法是运行在命令行模式,做一些类似如下:

% Define stop times and preallocate a cell array to save the simstates
stop_times = 1:10; % one second intervals upto 10 seconds
sim_states = cell(1,numel(stop_times));

% Run the model in a loop, saving the simstate at the required times
for tdx = 1:numel(stop_times)

   if tdx == 1
      % First simulation
      sim_out = sim('mdl_name', 'StopTime', num2str(stop_times(tdx)), 'SaveFinalState', 'on', ...
             'LoadInitialState', 'off', 'SaveCompleteFinalSimState', 'on',...
             'FinalStateName', 'final_simstate');
   else
      % subsequent simulations
      assignin('base', 'new_simstate', sim_states{tdx-1});
      sim_out = sim('mdl_name', 'StartTime', num2str(stop_times(tdx-1)),...
             'StopTime', num2str(stop_times(idx)), 'SaveFinalState', 'on', ...
             'LoadInitialState', 'on','InitialState', 'new_simstate',...
             'SaveCompleteFinalSimState', 'on',...
             'FinalStateName', 'final_simstate');
   end

   % store the simstate
   sim_states{tdx} = sim_out.get('final_simstate');
end

上述代码假定变量从qazxsw POI的工作区加载,但可以很容易地被修改以从模型工作区或工作区的功能得到它。

© www.soinside.com 2019 - 2024. All rights reserved.