Array indices must be positive integers or logical values.

hello,
Trying to plot but I'm having a indexing issue while using meshgrid. I needed theta to have the same dimensions as R_mesh and Z_mesh but when I meshgrid the theta variable I get the "Array indices must be positive integers or logical values." error on the function below.
Here is what I have:
r = (0:1:500);
z = (-250:1:50);
theta = (0:.0209:2*pi);
[R_mesh,Z_mesh]= meshgrid(r,z);
[R_2,theta_mesh]= meshgrid(r,theta);
% Z source
z_s = -20;
% Wave length and number
lamda = 2;
k = 2*pi/lamda;
% Spherical Wave convertion
R1 = sqrt(R_mesh.^(2)+(Z_mesh+z_s).^2);
R = R1 + z_s.*sin(theta_mesh);
% Approxamate Lloyd Mirror Function to create plot
Approx_Mirror_Func = 1./R((exp((1i*k.*(R-z_s.*sin(theta_mesh)))))-...
(exp((1i*k.*(R+z_s.*sin(theta_mesh))))));
% Transmission Loss Factor
TL_Approx = -10*log10(abs(Approx_Mirror_Func/1).^2);
% Plot of the function
figure('Name','Question 1b','NumberTitle','off')
pcolor(r,z,TL_Approx)
Any help would be appreciated. Thanks

2 Comments

You use the meshgrid values to generate the points at which the function is to be evaluated; then you plot the result of that evaluation.
Approx_Mirror_Func = 1./R((exp((1i*k.*(R-z_s.*sin(theta_mesh)))))-...
(exp((1i*k.*(R+z_s.*sin(theta_mesh))))));
It's not R((exp(...) which is using the expression as a subscript into the R array that you want above but R and some other mathematical function; I'm not sure just what but maybe simply ".*" to multiply by the exponential?
Adding the "*" to the the equation fixed the array issue. thanks.

Sign in to comment.

Answers (0)

Tags

Asked:

on 7 Oct 2018

Commented:

on 7 Oct 2018

Community Treasure Hunt

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

Start Hunting!