Azzera filtri
Azzera filtri

Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

Not enough input arguments

1 visualizzazione (ultimi 30 giorni)
tevzia
tevzia il 21 Giu 2013
Chiuso: MATLAB Answer Bot il 20 Ago 2021
Hi, I try to create a genetic algorithm model and i try to create a fitness function to calculate fitness of every child. However, Matlab gives a function input error.
Here is the code that I wrote so far,
_
function [ fitness ] = calcfitness( breedingpop, nbreeding, penalty )
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
for i=1:nbreeding
fitness = (breedingpop(nbreeding).penalty - breedingpop(i).penalty) / (breedingpop(nbreeding).penalty - breedingpop(1).penaltybreedingpop)
end
i know "penalty" is not the correct way to add as an argument. Does anyone have any idea how I could add penalty as an argument. Thanks

Risposte (1)

Azzi Abdelmalek
Azzi Abdelmalek il 21 Giu 2013
Modificato: Azzi Abdelmalek il 21 Giu 2013
function [ fitness ] = calcfitness( breedingpop, nbreeding, penalty )
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
for i=1:nbreeding
fitness = (breedingpop(nbreeding).(penalty) - breedingpop(i).penalty) / (breedingpop(nbreeding).(penalty) - breedingpop(1).penaltybreedingpop)
end
penalty should be a strindg
  6 Commenti
tevzia
tevzia il 21 Giu 2013
in the main code
childfitness = calcfitness(breedingpop, nbreeding, penalty )
Azzi Abdelmalek
Azzi Abdelmalek il 21 Giu 2013
penalty should be a string
childfitness = calcfitness(breedingpop, nbreeding, 'penalty' )

Questa domanda è chiusa.

Community Treasure Hunt

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

Start Hunting!

Translated by