Subscripted assignment dimension mismatch

조회 수: 5 (최근 30일)
trilochan
trilochan 2013년 10월 14일
댓글: trilochan 2013년 10월 14일
hi i'm new to Matlab and i am working on a project in genetic algorithm. i'm getting an error saying Subscripted assignment dimension mismatch. can anyone tell me what does this error means. this is my objective function
function f = myfunction(x)
cc= (-138.71*log(x))+1727.1;
sv=0.1*cc;
i=0.06;
LT=15;
f(x) = ((cc*x)-((sv*x)*(1/((1+i)^LT))))*((i*(1+i)^LT)/(((i+1)^LT)-1));

채택된 답변

Walter Roberson
Walter Roberson 2013년 10월 14일
Why are you assigning the output to f(x) and not to f alone?
You should be considering whether x can ever be a 2D array. If it can, then your cc would be a 2D array, and then cc*x would be matrix multiplication rather than element-by-element multiplication; the same with sv*x
I note, by the way, that it would be more efficient to calculate (1+i)^LT once and then use the resulting variable three times in your f(x) instead of those several occurrences of the expression.
  댓글 수: 1
trilochan
trilochan 2013년 10월 14일
thank you very much walter. will keep in touch

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Genetic Algorithm에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by