Array elements are recalculated every iteration
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
VBBV
2023-4-5
编辑:VBBV
2023-4-5
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 个评论
VBBV
2023-4-5
logTable = num2cell([t*ones(length(y(:)),1) y(:)]);
Change also this line as above
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!