Array indices must be positive integers or logical values
Afficher commentaires plus anciens
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');
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Earth and Planetary Science dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!