Not enough input arguments

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일

0 개 추천

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

I know input arguments should be string but the penalty is a value that i calculate for every individuals in the model and i try to compare them (fitness) but I cannot figure out how to add argument for this functions.
% code
function [ fitness ] = calcfitness(breedingpop, nbreeding)
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
for i = 1:nbreeding
fitness = (breedingpop(nbreeding).penalty - breeding(i).penalty) / (breedingpop(nbreeding).penalty - breedingpop(1).penalty);
% code
for this variable "breedingpop(nbreeding).penalty" of function, what should i add as an argument. Sorry I am new user of matlab Thanks
Did you read my answer?
use
breedingpop(nbreeding).(penalty) % instead of
breedingpop(nbreeding).penalty
tevzia
tevzia 2013년 6월 21일
yes i did but i didnt work as well
Azzi Abdelmalek
Azzi Abdelmalek 2013년 6월 21일
How did you call your function?
in the main code
childfitness = calcfitness(breedingpop, nbreeding, penalty )
penalty should be a string
childfitness = calcfitness(breedingpop, nbreeding, 'penalty' )

이 질문은 마감되었습니다.

태그

질문:

2013년 6월 21일

마감:

2021년 8월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by