# assigning element in 3D matrix

2 views (last 30 days)
Abdulrahman Mohamed on 19 Mar 2022
I need to assign element in 3 D matrix that have size (x,y,z)
Index in position 3 exceeds array bounds (must not exceed 1).
for example
nz =3
nx=2
ny=3
Tz_D = zeros(nx,ny,nz);
mobility_X = Kx./(B_O.*mu); % (nx,ny,nz)
mobility_Y = Ky./(B_O.*mu); % (nx,ny,nz)
mobility_Z = Kz./(B_O.*mu); % (nx,ny,nz)
for i = 1:nx
for j=1:ny
for k=1:nz
if k < nz
Tfz_U(i,j,k) = 2* mobility_Z(:,:,k+1)* mobility_Z(:,:,k)/( mobility_Z(:,:,k+1)+ mobility_Z(k,:,:)); %Tf_k- %Tf_k-
Tz_U(i,j,k) = 0.00633*Tgz*Tfz_U(i,j,k);
% T_j-

Sulaymon Eshkabilov on 19 Mar 2022
First of all, you need to close the loops with "end" in your code, i.e.:
nz =3;
nx=2;
ny=3;
Tz_D = zeros(nx,ny,nz);
mobility_X = Kx./(B_O.*mu); % (nx,ny,nz)
mobility_Y = Ky./(B_O.*mu); % (nx,ny,nz)
mobility_Z = Kz./(B_O.*mu); % (nx,ny,nz)
for i = 1:nx
for j=1:ny
for k=1:nz
if k < nz
Tfz_U(i,j,k) = 2* mobility_Z(:,:,k+1)* mobility_Z(:,:,k)/( mobility_Z(:,:,k+1)+ mobility_Z(k,:,:)); %Tf_k- %Tf_k-
Tz_U(i,j,k) = 0.00633*Tgz*Tfz_U(i,j,k);
end
end
end
end
Note what are Kx, Ky, Kz, B_O, mu, Tgz, Tfz_U?
Abdulrahman Mohamed on 19 Mar 2022
Kx = 70; %md
Ky = 70; %md
Kz = 7; %md
mu = zeros(nx,ny,nz); % viscosity, cp
B_O = zeros(nx,ny,nz); % gravity, psia/ft: rho/144
tgz is just geometric area
just number

### Categories

Find more on Beamforming in Help Center and File Exchange

R2021a

### Community Treasure Hunt

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

Start Hunting!