How do i resolve the error in this code
6 ビュー (過去 30 日間)
古いコメントを表示
for t=2005:2015
Cost(t+1)=(C*exp(-1*r*t));
end
I am getting an error which says In assigning A(I)=B,the number of elements in I should be equal to B
0 件のコメント
回答 (2 件)
ES
2017 年 3 月 22 日
What are you trying to achieve in this code?
What your code does is to set Cost(0), Cost (1)...Cost(2005) to 0; And Cost(2006) to C*exp(-1*r*2005),
Cost(2007) to C*exp(-1*r*2007), so on till Cost(2016) to C*exp(-1*r*2015). Is this what you expect?
What are values of C and r? Are these arrays?
Guillaume
2017 年 3 月 22 日
The only way you can get this error is if one or both of C or r is not scalar. So what is
size(r)
size(C)
Your equation is basically creating a matrix or vector, which obviously can't be stored as a single element in Cost.
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!