Why do I get "Array indices must be positive integers or logical values"?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (2)
Dave B
el 11 de Oct. de 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 comentarios
Star Strider
el 11 de Oct. de 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 comentarios
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!