问题描述
晚上好,请问以下Matlab代码对您有帮助吗?在这里:
%% CLEAR ALL
close all
clear all
clc
%% LOAD MODEL AND LHC FILE
tic %start the clock
idx=1;
model = 'PG_PN_basic_rev1'; %This is the simulink file you wish to run.
load_system(model);
load 'LHC_input.mat' %Call in the file created by LHC_Final.m
LHC = (LHC1_input);
k_dc = LHC((1:5),1);
k_r = LHC((1:5),2);
a_1 = LHC((1:5),3);
b_1 = LHC((1:5),4);
Kg_PG = LHC((1:5),5);
Kg_PN = LHC((1:5),6);
for i = length(k_dc):-1:1
in(i) = Simulink.SimulationInput('PG_PN_basic_rev1');
in(i) = in(i).setVariable('k_dc',k_dc(i));
for j = length(k_r):-1:1
in(j) = in(j).setVariable('k_r',k_r(j));
for k = length(a_1):-1:1
in(k) = in(k).setVariable('a_1',a_1(k));
for l = length(b_1):-1:1
in(l) = in(l).setVariable('b_1',b_1(l));
for m = length(Kg_PG):-1:1
in(m) = in(m).setVariable('Kg_PG',Kg_PG(m));
for n = length(Kg_PN):-1:1
in(n) = in(n).setVariable('Kg_PN',Kg_PN(n));
end
end
end
end
end
end
out = parsim(in,'ShowProgress','on');
% eval(['PN_batch',int2str(idx),' =PN;']);
% data = eval(['PN_batch',int2str(idx)]);
% a{idx} = data;
% idx=idx+1;
% run = idx
timeElapsed = toc %How long did you code run for?
我希望能够在每次parsim运行时生成一个输出文件(PN_batch1,PN_batch2等)。但是,数据通常只属于1个输出,并且不会分成可读的工作空间对象,以后可以使用另一个脚本读取。任何建议将不胜感激。谢谢。
解决方法
out
是一个向量,其长度等于模拟次数,并且模拟数据存储在每个条目中。如果您的模型中有 to 个块,则可以使用out(10).NameOftoWorkspaceData
每次模拟访问该数据,以备获取第十次模拟的数据。在here上可以找到有关out
变量的更多信息。
提示:运行模型并检查变量out
,然后您可以探索其结构