Accessing parsim Output Data

5 ビュー (過去 30 日間)
John Grant
John Grant 2020 年 9 月 8 日
回答済み: Sulaymon Eshkabilov 2020 年 9 月 9 日
Good evening,
May I please get advice with the following code? Here it is:
%% 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?
The above code is running a Simulink file using the given variables (Kg_PN, Kg_PG, a_1, b_1, k_r, k_dc). These variables are making use of a table of values, and in theory, I should be inputting the first 5 rows of that table (as far as I can tell, it is). However, if you look at the commented out code, I wish to assign all the simulation run outputs to "PN", such that I can display that data later. How would I be able to store the simulation outputs into PN?

回答 (1 件)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2020 年 9 月 9 日
hi,
You can make some changes in your shown code:
  1. Call the variable series of "in" computed within for .. end loop. Like: In1(i), In2(j), In3(k), etc instead of in(i), in(j), in(k),
  2. Use a cell array to augment all under one variable, e.g.: PN{1} = In1; PN{2} = In2; PN{3} = In3, etc.
  3. Then you can plot the collected variables from PN cell array.

カテゴリ

Help Center および File ExchangeDeployment, Integration, and Supported Hardware についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by