MATLAB: I am calling function in GA Program but getting error

job shop code using genetic algorithm

[c,d]=crossover(a,b)
Data of crossover.m file is as under % Crossover operator
function [c,d]=crossover(a,b)
nn=length(a)-1;
% generating a random crossover point
cpoint=floor(nn*rand)+1;
c=[a(1:cpoint) b(cpoint+1:end)];
d=[b(1:cpoint) a(cpoint+1:end)];
end
% end for crossover
when i run the program i get this in return from command prompt "Error: File: GA.m Line: 169 Column: 2 This statement is not inside any function. (It follows the END that terminates the definition of the function "bintodec".)"
Please tell where the problem

Best Answer

Bilal Khurshid you are calling the functions crossover and mutate, after the end of function GA.m. You cannot call a functions after ending a function. You can write the definition of the functions after end of main function, but you cannot call it. Change the location of those two functions; place them where you want to call/use them. In the attached code, I have changed their position, that error is not showing out now.