필터 지우기
필터 지우기

Index exceeds the number of array elements - water balance for euler loop

조회 수: 1 (최근 30일)
NOtway
NOtway 2022년 10월 16일
답변: Torsten 2022년 10월 16일
I am constructing a water balance within a euler loop
for i=1:nt
time(i+1) = time(i) + dt;
% Determine lake overflow for each timestep
if V(i) + RAINFALL(i+1) - EVAP(i+1) >= V_max
Overflow(i+1) = V(i) + RAINFALL(i+1) - EVAP(i+1) - V_max;
else
Overflow(i+1) = 0;
end
Where V(i) is:
dV(i) = (RAINFALL(i) * A_catch * C / 1000) - Overflow(i) - (EVAP(i) * A / 1000); % units = m3
V(i+1) = V(i) + dt * dV(i); % volume lake in m3
The Overflow, RAINFALL and EVAP must all be applied to the same timestep (ie water overflows at the same time the lake capacity is exceeded, not in the next timestep)
However, I am getting the error "Index exceeds the number of array elements. Index must not exceed 3650"
The RAINFALL and EVAP data are both stored in 1x3650 interpolated vectors that have been extracted from an excel sheet
[date, t, Rainfall, Evap, I_t] = readvars("BOM_Data.xlsx"); %load daily data
%define desired timestep (10 points per day)
dt = 0.1; % step size (days)
time = 1:dt:(size(t,1)+0.9); % the range of time (days) (1.0 t0 365.9)
%interpolated vectors
RAINFALL = interp1(t,Rainfall,time);
EVAP = interp1(t,Evap,time);
Any suggested workarounds for getting this water balance to run? I assume the error is due to using i+1 in the water balance eq's, but I'm not sure how else to make sure that the overflow is applied in the correct timesteps.

답변 (1개)

Torsten
Torsten 2022년 10월 16일
Replace
for i=1:nt
by
for i=1:nt-1

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by