Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Not enough input arguments

2 ビュー (過去 30 日間)
tevzia
tevzia 2013 年 6 月 21 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
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

回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 6 月 21 日
編集済み: Azzi Abdelmalek 2013 年 6 月 21 日
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 件のコメント
tevzia
tevzia 2013 年 6 月 21 日
in the main code
childfitness = calcfitness(breedingpop, nbreeding, penalty )
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 6 月 21 日
penalty should be a string
childfitness = calcfitness(breedingpop, nbreeding, 'penalty' )

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by