Error: Array indices must be positive integers or logical values.
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have the following code:
theta = [0,45,60]
for i =1:3
if i-1 == 0;
theta(i-1) = 0
end
end
x=cosd(theta(i-1))
end
I keep getting the same error, I think its because you can't have an array of elements with an element at position zero, but I have already specified what I want it to be when that happens. Howc an I fix this?
0 commentaires
Réponses (2)
Ameer Hamza
le 29 Oct 2020
Modifié(e) : Ameer Hamza
le 29 Oct 2020
I am not sure what you are trying to do in your code. The following should work just fine
theta = [0,45,60]
x = cosd(theta)
0 commentaires
David Hill
le 29 Oct 2020
You are still indexing at zero. If you just want cosd at each theta then:
x=cosd(theta);
2 commentaires
David Hill
le 29 Oct 2020
Matlab does not allow indexing at zero. Indexing starts at 1. You never need to index at zero (you can always get around it).
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements 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!