Array indices must be positive integers or logical values.

1 vue (au cours des 30 derniers jours)
Polo
Polo le 7 Oct 2018
Commenté : Polo le 7 Oct 2018
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 commentaires
dpb
dpb le 7 Oct 2018
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?
Polo
Polo le 7 Oct 2018
Adding the "*" to the the equation fixed the array issue. thanks.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by