Array elements are recalculated every iteration

2 vues (au cours des 30 derniers jours)
Zakaria OUAOUJA
Zakaria OUAOUJA le 5 Avr 2023
Commenté : VBBV le 5 Avr 2023
I am trying to calculate Tprod using waklkin temperature calculated by an other shoftware using the code below, which recalculates all elements of the Tprod array in every iteration as shown below.
How can I modify my code to calculate only one Tprod(i,j) at each time step using a single Twalkin(i,j), instead of recalculating the entire Tprod array every iteration?
nRows = ceil(endTime / ep.timestep); %Query timestep after mlep initialization
%logTable
logTable = table('Size',[0, 1 + ep.nOut],...
'VariableTypes',repmat({'double'},1,1 + ep.nOut),...
'VariableNames',[{'Time'}; ep.outputSigName]);
iLog = 1;
% Start the co-simulation process and communication.
ep.start
%Data
t = 0; h=10 ; s= 1; m=100 ; cp= 3230; Tprodi= 30;
% The simulation loop
while t < endTime
% Specify inputs
u = [200]; % Initial value to be sent to EnergyPlus
% Send inputs & get outputs from EnergyPlus
y = ep.step(u);
% Obtain elapsed simulation time
t = ep.time; %[s]
% Walkin Temperature
Twalkin= table2array(logTable(:,2:2))
Q=m*cp*(Tprod - Twalkin);
% Product Temperature
Tprod = Twalkin + (Tprodi - Twalkin)*exp(-t*(h*s)/(m*cp))
logTable(iLog, :) = num2cell([t y(:)']);
iLog = iLog + 1;
end
Twalkin =
-20.1041
Tprod =
29.9070
_________________
Twalkin =
-20.1041
-19.2153
Tprod =
29.8142
29.8175
_________________
Twalkin =
-20.1041
-19.2153
-18.6658
Tprod =
29.7216
29.7265
29.7296
_________________
Twalkin =
-20.1041
-19.2153
-18.6658
-18.2641
Tprod =
29.6291
29.6357
29.6397
29.6427

Réponses (1)

VBBV
VBBV le 5 Avr 2023
Modifié(e) : VBBV le 5 Avr 2023
This is one approach, where you can initialize a variable k and iterate along the time step
nRows = ceil(endTime / ep.timestep); %Query timestep after mlep initialization
%logTable
logTable = table('Size',[0, 1 + ep.nOut],...
'VariableTypes',repmat({'double'},1,1 + ep.nOut),...
'VariableNames',[{'Time'}; ep.outputSigName]);
iLog = 1;
% Start the co-simulation process and communication.
ep.start
%Data
t = 0; h=10 ; s= 1; m=100 ; cp= 3230; Tprodi= 30;
% The simulation loop
k = 1;
while t < endTime
% Specify inputs
u = [200]; % Initial value to be sent to EnergyPlus
% Send inputs & get outputs from EnergyPlus
y = ep.step(u);
% Obtain elapsed simulation time
t = ep.time; %[s]
% Walkin Temperature
Twalkin= table2array(logTable(:,2:2))
% Product Temperature
Tprod(iLog,k) = Twalkin(iLog,2) + (Tprodi - Twalkin(iLog,2))*exp(-t*(h*s)/(m*cp))
logTable(iLog, :) = num2cell([t y(:)']);
iLog = iLog + 1;
k = k+1;
end
  2 commentaires
Zakaria OUAOUJA
Zakaria OUAOUJA le 5 Avr 2023
Thank you for your answer.
I have tried to ran the scripte with the modification you suggested and display the following error.
Index in position 2 exceeds array
bounds (must not exceed 1).
Error in mlepMatlab_example (line74)
Tprod(iLog,k) = Twalkin(iLog,2) + (Tprodi - Twalkin(iLog,2))*exp(-t*(h*s)/(m*cp));
VBBV
VBBV le 5 Avr 2023
logTable = num2cell([t*ones(length(y(:)),1) y(:)]);
Change also this line as above

Connectez-vous pour commenter.

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by