So I am trying to create an easy function to calculate an equation for all the values between 0 and 90 degrees, in order to create a plot of the Earth dipole field for different altitudes, but I keep getting the same error message:
Array indices must be positive integers or logical values.
I have tried different approaches, but I am not able to make it work. If I don't store the values for the plot, the loop runs and gives me the correct values, but the moment I try to store them to plot them all together, it gives me the error. Can somebody help?
clear all; clc;
nu0 = 1.256637*10^-6;
m = 8*10^22;
h = 400;
r = 6378 + h;
rm = r*1000;
for i = 0:0.1:90
B = (nu0/(4*pi))*(m/rm^3)*sqrt(1+3*sind(i)^2);
Bplot(i) = B;
grid on; hold on;
plot(B,i,'b-','Displayname','Magnitude of the dipole field');