Array elements are recalculated every iteration
2 ビュー (過去 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 で Pattern Recognition and Classification についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!