Effacer les filtres
Effacer les filtres

Array indices must be positive integers or logical values.

3 vues (au cours des 30 derniers jours)
Kyle Lazaroff
Kyle Lazaroff le 11 Déc 2019
Commenté : Kyle Lazaroff le 11 Déc 2019
im not sure why i keep getting this error, if someone could show me how to fix it that would be great. The error is for l_2, i made l_1 and l_2 to see where the error was coming from.
clear
clc
r_d = 1.50e11; % distance from Earth to Sun
r_s = (1.39e9)/2; % radius of the sun
fw =(r_s/r_d)^2;
t_s = 5800; % temp in kelvin
lamda = 0:0.01:3;
h = 6.626e-34; % in J*s
k_b = 1.381e-23; % in J/K
c = 2.998e8; % in m/s
l_1 = (2*pi*h*c.^2)\lamda.^5;
l_2 = 1\exp((h*c)\(lamda*k_b*t_s))-1;
l_sun(lamda) = fw.*l_1.*l_2;

Réponse acceptée

ME
ME le 11 Déc 2019
I just ran this segment of code and I get the same "Array indices must be positive integers or logical values." error but for the l_sun(lamda) line. The issue there is that in Matlab array indices may only take positive integer values. In your example you are trying to use lamda = 0, 0.1, 0.2... as indices and Matlab is not able to handle them. The line for l_2 runs absolutely fine for me.

Plus de réponses (1)

Bandar
Bandar le 11 Déc 2019
Indices must be postivie integer. In your code, lambda is a vector that contains non-integers.
lamda = 0:0.01:3;
...
l_sun(lamda) = fw.*l_1.*l_2; % <-- here is the problem in l_sun(lamda)
  1 commentaire
Kyle Lazaroff
Kyle Lazaroff le 11 Déc 2019
how do you convert the lamda vector into integers?

Connectez-vous pour commenter.

Catégories

En savoir plus sur Data Type Conversion dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by