## Index in position 1 is invalid. Array indices must be positive integers or logical values.

Hello MathWorks Community,

I am running into an issue where I am trying to plot a function that has two variables.

I attached my code in the description:

E_Plane_H_Plane.m

I calculate my U_Rad_Norm_dB and it is in terms of theta and phi.

My theta variable is an array of values:

theta = 0:0.01:pi/2

The phi variable has "fixed" values

phi_E_1 = 0;

phi_E_2 = pi;

phi_H_1 = pi/2;

phi_H_2 = 3*(pi/2);

What I am trying to plot is:

1) E_Plane_1 = U_Rad_Norm_dB(theta,phi_E_1);

2) E_Plane_2 = U_Rad_Norm_dB(theta,phi_E_2);

3) H_Plane_1 = U_Rad_Norm_dB(theta,phi_H_1);

4) H_Plane_2 = U_Rad_Norm_dB(theta,phi_H_2);

My issue is that I calculate U_Rad_Norm_dB through several different variables. I’m not sure how to change it into a "function" to where I can "plug in" my "theta array" and my individual "phi" values.

When I try to use a for loop, it gives me the error:

Index in position 1 is invalid. Array indices must be positive integers or logical values.

I’ve tried to create a function previously for this, but it hasn’t worked and it made things more difficult when I was trying to pass my (theta,phi) values.Hello MathWorks Community,

I am running into an issue where I am trying to plot a function that has two variables.

I attached my code in the description:

E_Plane_H_Plane.m

I calculate my U_Rad_Norm_dB and it is in terms of theta and phi.

My theta variable is an array of values:

theta = 0:0.01:pi/2

The phi variable has "fixed" values

phi_E_1 = 0;

phi_E_2 = pi;

phi_H_1 = pi/2;

phi_H_2 = 3*(pi/2);

What I am trying to plot is:

1) E_Plane_1 = U_Rad_Norm_dB(theta,phi_E_1);

2) E_Plane_2 = U_Rad_Norm_dB(theta,phi_E_2);

3) H_Plane_1 = U_Rad_Norm_dB(theta,phi_H_1);

4) H_Plane_2 = U_Rad_Norm_dB(theta,phi_H_2);

My issue is that I calculate U_Rad_Norm_dB through several different variables. I’m not sure how to change it into a "function" to where I can "plug in" my "theta array" and my individual "phi" values.

When I try to use a for loop, it gives me the error:

Index in position 1 is invalid. Array indices must be positive integers or logical values.

I’ve tried to create a function previously for this, but it hasn’t worked and it made things more difficult when I was trying to pass my (theta,phi) values. Hello MathWorks Community,

I am running into an issue where I am trying to plot a function that has two variables.

I attached my code in the description:

E_Plane_H_Plane.m

I calculate my U_Rad_Norm_dB and it is in terms of theta and phi.

My theta variable is an array of values:

theta = 0:0.01:pi/2

The phi variable has "fixed" values

phi_E_1 = 0;

phi_E_2 = pi;

phi_H_1 = pi/2;

phi_H_2 = 3*(pi/2);

What I am trying to plot is:

1) E_Plane_1 = U_Rad_Norm_dB(theta,phi_E_1);

2) E_Plane_2 = U_Rad_Norm_dB(theta,phi_E_2);

3) H_Plane_1 = U_Rad_Norm_dB(theta,phi_H_1);

4) H_Plane_2 = U_Rad_Norm_dB(theta,phi_H_2);

My issue is that I calculate U_Rad_Norm_dB through several different variables. I’m not sure how to change it into a "function" to where I can "plug in" my "theta array" and my individual "phi" values.

When I try to use a for loop, it gives me the error:

Index in position 1 is invalid. Array indices must be positive integers or logical values.

I’ve tried to create a function previously for this, but it hasn’t worked and it made things more difficult when I was trying to pass my (theta,phi) values. for loop, iterations, plot, e plane, h plane, plotting MATLAB Answers — New Questions