필터 지우기
필터 지우기

Array elements are recalculated every iteration

조회 수: 2 (최근 30일)
Zakaria OUAOUJA
Zakaria OUAOUJA 2023년 4월 5일
댓글: VBBV 2023년 4월 5일
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

답변 (1개)

VBBV
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
Zakaria OUAOUJA
Zakaria OUAOUJA 2023년 4월 5일
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 2023년 4월 5일
logTable = num2cell([t*ones(length(y(:)),1) y(:)]);
Change also this line as above

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Pattern Recognition and Classification에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by