Why does matlab return "Index exceeds matrix dimensions"?

1 回表示 (過去 30 日間)
Cantor Set
Cantor Set 2019 年 9 月 1 日
編集済み: Cantor Set 2019 年 9 月 1 日
Hello,
Nind=2; %number of vectors
Nvar=2; %number of variables in each vector
perci=3; %number of bits of every variable
ph=zeros(Nind, Nvar);
ch=crtbp(Nind, Nvar*perci); %random binary matrix and crtbp is a function from
%genetic algorithm MATLAB toolbox
for i=1:Nind
s=1; E=perci;
for j=1:Nvar
d=ch(i,s:E)
s=E+1; E=s+ perci;
phen(i,j)=bi2de(d)
j=j+1;
end
i=i+1;
end
ph
The aim of the code is to take in the ith row of ch, the first perci bits which is a binary row vector and convert it to a real number then take this real number and put it in ph, then in the same ith row in ch take the 2nd perci bit namely, perci+1 to 2*perci +1 and convert it to a real number and put it into ph and so on
whenever i run the code it tells me "Index exceeds matrix dimensions."
I don't know why
  2 件のコメント
Walter Roberson
Walter Roberson 2019 年 9 月 1 日
Where are you finding crtbp() ? Are you using the third-party gatbx package, which you can download from http://www.acse.dept.shef.ac.uk/cgi-bin/gatbx-download ?
Cantor Set
Cantor Set 2019 年 9 月 1 日
編集済み: Cantor Set 2019 年 9 月 1 日
Hello Roberson,
Yes, I used the crtbp function in the GA toolbox. But, when I run the code it was telling me
"Index exceeds matrix dimensions" refering to the line
d=ch(i,s:E)
But, I solved it. It was a careless calculation problem.
Thank you!

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by