Attempted to access x(2); index out of bounds because numel(x)=1.

조회 수: 1 (최근 30일)
nesrine nesrine
nesrine nesrine 2014년 8월 13일
답변: dpb 2014년 8월 14일
Hello, I have the problem of dimensions when executing the function of Genetic algorithms
how can I solve this problem :
'Attempted to access x(2); index out of bounds because numel(x)=1'
here is the code :
function L=ga1(x)
load FM.mat;
load L0.mat;
load Lmsd.mat;
load Lrst.mat;
FM=FM(:,1);
L0=L0(:,1);
Lrst=Lrst(:,1);
Lmsd=Lmsd(:,1);
FT=x(1)*L0+x(2)*Lrst+x(3)*Lmsd;
L=abs(FM-FT);
end

답변 (1개)

dpb
dpb 2014년 8월 14일
'Attempted to access x(2); index out of bounds because numel(x)=1'
function L=ga1(x)
..
FT=x(1)*L0+x(2)*Lrst+x(3)*Lmsd;
...
You passed only a single value for x when you called your function gal. Must have at least three elements by your expression above.

카테고리

Help CenterFile Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by