フィルターのクリア

index exceeds matrix dimensions

7 ビュー (過去 30 日間)
Tarun Pandey
Tarun Pandey 2020 年 11 月 21 日
編集済み: ag 2024 年 9 月 24 日 10:59
%consolidation for PTPB
H=10; % total depth of section
Cv=0.5; %in m^2/day
U0=100; %initial U
U1s=0;
U2s=0;
dz=1; % depth of interval
n=H/dz; %no. of depth intervals
t=40; %time in days
dt=1; %time interval
m=t/dt; %total no. of time intervals
Yw=9.81; %in KN/m2
U=zeros(n,m);
i1=input('give value of thresold gradient');
i1=fprintf('i1= %d \n',i1);
a=input('give value of a= %d');
a=fprintf('a= %4d \n',a);
alpha=input('Enter value of alpha= %5d');
alpha= fprintf('alpha = %d \n',alpha);
M=zeros(n,m);
j=0;
for l=dt:dt:39*dt
j=j+1;
for i=2:n
M(i,j)=1-(1-a)*alpha*(1-exp((-alpha/(i1*Yw)*(U(i+1,j)-U(i-1,j))/(2*dz))));
end
end

回答 (1 件)

ag
ag 2024 年 9 月 24 日 10:58
編集済み: ag 2024 年 9 月 24 日 10:59
Hi Tarun,
I understand that you are encountering the "Index exceeds array bounds" error while executing the shared script. This issue occurs in the following segment of the code:
for i = 2:n
M(i, j) = 1 - (1 - a) * alpha * (1 - exp((-alpha / (i1 * Yw) * (U(i+1, j) - U(i-1, j)) / (2 * dz))));
end
The error arises because the loop iterates from `i = 2` to `n`, while the matrix `U` has a size of `n`. Therefore, attempting to access the element at the `i+1` index exceeds the array bounds.
To address this issue, you may either increase the size of the matrix `U` by 1 or adjust the loop to iterate until `n-1`, depending on what best suits your requirements.
Hope this helps!

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by