How do i resolve the error in this code

조회 수: 6 (최근 30일)
Felicity Kaseke
Felicity Kaseke 2017년 3월 22일
답변: Guillaume 2017년 3월 22일
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

답변 (2개)

ES
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?
  댓글 수: 2
Felicity Kaseke
Felicity Kaseke 2017년 3월 22일
I want the code to calculate the costs for each year, r=0.05 and C is an equation given by C= CR + CP(x(1) + a0*x(2)), where a0 is a constant
ES
ES 2017년 3월 22일
is C an array?

댓글을 달려면 로그인하십시오.


Guillaume
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.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by