Why do I get "Array indices must be positive integers or logical values"?
1 view (last 30 days)
Show older comments
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 Comments
Answers (2)
Dave B
on 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 Comments
Star Strider
on 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 Comments
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!