MATLAB: How to create a loop where I am populating the 200×100 LpTot matrix but pulling values from the 13×3 Z matrix

for loopMATLABmatrix

I am populating a 200×100 grid with propagating sound from 13 noise sources. I am struggling to create a loop where the values from Z are being used in the equation for sound pressure (Lp). The form of what I would expect the loop to look like is:
% FORMAT OF THE SOUND PRESSURES BELOW ARE AS STATED HERE:

% Rx = sqrt((X-Z(x,1)).^2 + (Y-Z(x,2)).^2);

%



% Lwx = Z(x,3);

%
% Lpx = Lwx - 10*log10(2*pi*Rx.^2);

And I would require a loop to create LpTot which is a 200×100 matrix which has been logarithmically added from the 200×100 matrices of Lp1 to Lp13. Some errors I have received from trying to loop are "Index exceeds matrix dimensions" and "Subscripted assignment dimension mismatch".
Here is my current working code, many thanks:
res = 10;
L = 0:res:2000; %x direction (2000m)
W = 0:res:1000; %y direction (1000m)
[X,Y] = meshgrid(L,W);
% x y Lw Source #
Z = [1855 955 117 % 1

115 565 119 % 2
1655 515 113 % 3

315 465 117 % 4

1855 415 119 % 5

515 365 114 % 6

1005 315 120 % 7

715 265 122 % 8

815 215 128 % 9

915 165 108 % 10

1015 115 115 % 11

1115 65 116 % 12

1215 15 119] % 13
% FORMAT OF THE SOUND PRESSURES BELOW ARE AS STATED HERE:
% Rx = sqrt((X-Z(x,1)).^2 + (Y-Z(x,2)).^2);
%
% Lwx = Z(x,3);
%
% Lpx = Lwx - 10*log10(2*pi*Rx.^2);
% SOURCE 1
Lp1 = Z(1,3) - 10*log10(2*pi*(sqrt((X-Z(1,1)).^2 + (Y-Z(1,2)).^2)).^2);
% SOURCE 2
Lp2 = Z(2,3) - 10*log10(2*pi*(sqrt((X-Z(2,1)).^2 + (Y-Z(2,2)).^2)).^2);
% SOURCE 3
Lp3 = Z(3,3) - 10*log10(2*pi*(sqrt((X-Z(3,1)).^2 + (Y-Z(3,2)).^2)).^2);
% SOURCE 4
Lp4 = Z(4,3) - 10*log10(2*pi*(sqrt((X-Z(4,1)).^2 + (Y-Z(4,2)).^2)).^2);
% SOURCE 5
Lp5 = Z(5,3) - 10*log10(2*pi*(sqrt((X-Z(5,1)).^2 + (Y-Z(5,2)).^2)).^2);
% SOURCE 6
Lp6 = Z(6,3) - 10*log10(2*pi*(sqrt((X-Z(6,1)).^2 + (Y-Z(6,2)).^2)).^2);
% SOURCE 7
Lp7 = Z(7,3) - 10*log10(2*pi*(sqrt((X-Z(7,1)).^2 + (Y-Z(7,2)).^2)).^2);
% SOURCE 8
Lp8 = Z(8,3) - 10*log10(2*pi*(sqrt((X-Z(8,1)).^2 + (Y-Z(8,2)).^2)).^2);
% SOURCE 9
Lp9 = Z(9,3) - 10*log10(2*pi*(sqrt((X-Z(9,1)).^2 + (Y-Z(9,2)).^2)).^2);
% SOURCE 10
Lp10 = Z(10,3) - 10*log10(2*pi*(sqrt((X-Z(10,1)).^2 + (Y-Z(10,2)).^2)).^2);
% SOURCE 11
Lp11 = Z(11,3) - 10*log10(2*pi*(sqrt((X-Z(11,1)).^2 + (Y-Z(11,2)).^2)).^2);
% SOURCE 12
Lp12 = Z(12,3) - 10*log10(2*pi*(sqrt((X-Z(12,1)).^2 + (Y-Z(12,2)).^2)).^2);
% SOURCE 13
Lp13 = Z(13,3) - 10*log10(2*pi*(sqrt((X-Z(13,1)).^2 + (Y-Z(13,2)).^2)).^2);
% LP TOTAL
a = 10.^(Lp1/10); % 1
b = 10.^(Lp2/10); % 2
c = 10.^(Lp3/10); % 3
d = 10.^(Lp4/10); % 4
e = 10.^(Lp5/10); % 5
f = 10.^(Lp6/10); % 6
g = 10.^(Lp7/10); % 7
h = 10.^(Lp8/10); % 8
i = 10.^(Lp9/10); % 9
j = 10.^(Lp10/10); % 10
k = 10.^(Lp11/10); % 11
l = 10.^(Lp12/10); % 12
m = 10.^(Lp13/10); % 13
n = 10.^(Lp14/10); % 14
LpTot = 10*log10(a + b + c + d + e + f + g + h + i + j + k + l + m + n);
% PLOTS
% PCOLOR
p = pcolor(X,Y,LpTot);
set(p,'Edgecolor','none');
colormap(jet)
y = colorbar;
title('Visualisation of Sound Propagation');
xlabel('x - Position (m)');
ylabel(y,'dB','rotation',0);
ylabel('y - Position (m)');
% NUMBERING ON PCOLOR
Nums = {'1','2','3','4','5','6','7','8','9','10','11','12','13','14'};
for d = 1:length(Nums)
text(Z(d,1),Z(d,2)-20,Nums{d});
end
% MESH
mesh(X,Y,LpTot)
colormap(jet)
z = colorbar;
title('3-D Map of Noise Sources');
xlabel('x - Position (m)');
ylabel(z,'dB','rotation',0);
ylabel('y - Position (m)');
zlabel('Sound Pressure Level (dB)');

Best Answer

res = 10;
L = 0:res:2000; %x direction (2000m)
W = 0:res:1000; %y direction (1000m)
ny = length(L) ;
nx = length(W) ;
[X,Y] = meshgrid(L,W);
% x y Lw Source #
Z = [1855 955 117 % 1
115 565 119 % 2
1655 515 113 % 3
315 465 117 % 4
1855 415 119 % 5
515 365 114 % 6
1005 315 120 % 7
715 265 122 % 8
815 215 128 % 9
915 165 108 % 10
1015 115 115 % 11
1115 65 116 % 12
1215 15 119] % 13 ;
nz = size(Z,3) ;
% FORMAT OF THE SOUND PRESSURES BELOW ARE AS STATED HERE:
% Rx = sqrt((X-Z(x,1)).^2 + (Y-Z(x,2)).^2);
%

% Lwx = Z(x,3);
%
% Lpx = Lwx - 10*log10(2*pi*Rx.^2);
Lp = zeros(nx,ny,nz) ;
for i = 1:nz
Lwi = Z(i,3) ;
Ri = sqrt((X-Z(i,1)).^2 + (Y-Z(i,2)).^2);
Lp(:,:,i) = Z(i,3) - 10*log10(2*pi*(sqrt((X-Z(i,1)).^2 + (Y-Z(i,2)).^2)).^2) ;
Lp(:,:,i) = 10.^(Lp(:,:,i)/10) ;
end
LpTot = 10*log10(sum(Lp,3));
% PLOTS
% PCOLOR
p = pcolor(X,Y,LpTot);
set(p,'Edgecolor','none');
colormap(jet)
y = colorbar;
title('Visualisation of Sound Propagation');
xlabel('x - Position (m)');
ylabel(y,'dB','rotation',0);
ylabel('y - Position (m)');
% NUMBERING ON PCOLOR
% Nums = {'1','2','3','4','5','6','7','8','9','10','11','12','13','14'};
% for d = 1:length(Nums)
% text(Z(d,1),Z(d,2)-20,Nums{d});
% end
% % MESH
mesh(X,Y,LpTot)
colormap(jet)
z = colorbar;
title('3-D Map of Noise Sources');
xlabel('x - Position (m)');
ylabel(z,'dB','rotation',0);
ylabel('y - Position (m)');
zlabel('Sound Pressure Level (dB)');
welcome to MATLAB