Can someone explain why I am getting the error "Not enough input arguments (line 4)"?

1 view (last 30 days)
function YY = crossover(X,n)
% X = population
% n = Number of chromosomes to be crossed
[x1 y1] = size(X); LINE 4
Y = zeros(n,y1);
for z = 1:n
B = X(randi(x1),:); % select parent chromosome
r1 = 1 + randi(y1-1);
C = B(1,1:r1);
B(:,1:r1) = []; % cut
[x3 y3] = size(B);
B(1,y3+1:y1) = C;
Y(z,:) = B;
end
YY = Y;

Accepted Answer

Walter Roberson
Walter Roberson on 4 Aug 2021
You tried to run the function without passing any matrix to it, and matlab complained that it could not find any input being passed to it.
When a function requires parameters then you cannot just press the green Run button, and you cannot just give the name of the function by itself to run the function.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!