GA file exchange code need help

Hi there,
I am trying to modify the GA code (link above) by changing the population type using the following:
%generate population of 0s and 1s
%M=no. of chromosomes
%N=no. of genes in chromosomes
population = randi([0 1], M , N);
%for every 1 in population randomly assigns number between 1 to 15
population(population==1)=randi([1 15], 1, nnz(population));
it doesn't work as i get error "dot indexing not supported for this variable type"
can someone please help.

3 件のコメント

Walter Roberson
Walter Roberson 2019 年 10 月 2 日
It is not clear where you are putting that code. If you are putting it inside initialization() then the problem is that initialization() must return a struct looking like
population.Chromosomes(i).Gene(j) = value
but you are returning a pure numeric array.
Farah Mahmood
Farah Mahmood 2019 年 10 月 3 日
Yes i am trying to put it inside initilization. is it possible to convert numeric array to structure?
or how to include the type of data i am generating in this file exchange code?
I basically want to change the data and objective function.
Walter Roberson
Walter Roberson 2019 年 10 月 3 日
You can use num2cell with the dimension parameter to split by rows or columns giving a cell array. You can pass that cell array to struct() as the value, causing it to create one structure member for each cell entry.

回答 (0 件)

この質問は閉じられています。

質問済み:

2019 年 10 月 2 日

閉鎖済み:

2021 年 8 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by