Array indices must be positive integers or logical values

1 visualización (últimos 30 días)
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?
%% MAGNETORQUER SIZING
clear all; clc;
%% Magnitude of the Dipole Field:
nu0 = 1.256637*10^-6; % [H/m] Permeability of free space
m = 8*10^22; % [A m2] Earth's magnetic dipole moment
h = 400; % Altitude in [km]
r = 6378 + h; % Orbit radius in [km]
rm = r*1000; % Scaling to [m]
for i = 0:0.1:90
B = (nu0/(4*pi))*(m/rm^3)*sqrt(1+3*sind(i)^2);
Bplot(i) = B;
end
figure(1);
grid on; hold on;
plot(B,i,'b-','Displayname','Magnitude of the dipole field');

Respuesta aceptada

Alex Mcaulley
Alex Mcaulley el 12 de Ag. de 2019
You are trying to acces to: B(0), B(0.1) and so on, which are not allowed indexes. Try with this:
%% MAGNETORQUER SIZING
clear all; clc;
%% Magnitude of the Dipole Field:
nu0 = 1.256637*10^-6; % [H/m] Permeability of free space
m = 8*10^22; % [A m2] Earth's magnetic dipole moment
h = 400;
r = 6378 + h;
rm = r*1000;
i = 0:0.1:90
Bplot = (nu0/(4*pi))*(m/rm^3)*sqrt(1+3*sind(i).^2);
figure(1);
grid on; hold on;
plot(Bplot,i,'b-','Displayname','Magnitude of the dipole field');

Más respuestas (0)

Categorías

Más información sobre Earth and Planetary Science en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by