Why do I get "Array indices must be positive integers or logical values"?
2 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (2 件)
Star Strider
2021 年 10 月 11 日
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 件のコメント
Dave B
2021 年 10 月 11 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!