Matlab Arrays not populating correctly
Mostrar comentarios más antiguos
Hi all, I'm getting a problem with MATLAB where the values being inserted into a vector are appearing as [] instead of [rand, 0].
This is my code:
M = 10; %no of chromosomes (candidate solutions)
N = 2; %no of genes
for k = 1 : M
population.Chromosomes(M).Gene(:) = [rand, 0];
population.Chromosomes(k).fitness = fitnessFunction(population.Chromosomes(M).Gene(:) );
end
The matrix population.Chromosomes should show all the values in the gene column as [0.8344,0] for example, and I'm sure these cells have values as the fitness vector has a value.

Respuesta aceptada
Más respuestas (1)
dpb
el 4 de Nov. de 2020
You've got a typo...
population.Chromosomes(M).Gene(:) = [rand, 0];
is writing into the location M(=10) every time.
1 comentario
Cathal White
el 4 de Nov. de 2020
Categorías
Más información sobre Resizing and Reshaping Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!