Why do I get "Array indices must be positive integers or logical values"?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
clc
clear
R=1;
C=1;
vf=18;
ti=0;
tf=10;
h=0.5;
tao=R*C;
t=ti:h:tf;
vt=vf(1-exp(-t/tao));
tabla=[t' vt']
0 commentaires
Réponses (2)
Star Strider
le 11 Oct 2021
MATLAB does not recognise implicit multiplication, so the missing multiplication operator
vt=vf(1-exp(-t/tao));
↑ ← HERE
causes MATLAB to treat the contents of the parentheses as an array index, throwing the error.
This now works —
R=1;
C=1;
vf=18;
ti=0;
tf=10;
h=0.5;
tao=R*C;
t=ti:h:tf;
vt=vf*(1-exp(-t/tao));
tabla=[t' vt']
.
0 commentaires
Dave B
le 11 Oct 2021
You're getting this message because of the line:
vt=vf(1-exp(-t/tao));
vf is the number 18, or, more precisely it's a matrix of size 1,1 which contains the number 18. This syntax is interpeted as trying to take the value of vt in the index 1-exp(-t/tao), so if vt was [5 9 1] and you wrote vt(2), it would return 9. What do you want to accomplish in this line? If it's multiplication...
vt=vf*(1-exp(-t/tao));
0 commentaires
Voir également
Catégories
En savoir plus sur Matrix Indexing 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!