I get an error "Error : undefined function or variable 'randcoosen' " from line 1 and I dont fully understand what the lines 3 to 10 are doing? Thanks
1 view (last 30 days)
Show older comments
ma=RandChooseN(probs,M); --line1
pa=RandChooseN(probs,M); --line2
xp=ceil(rand(1,M)*(Nt-1)); --line3
pop(1:2:popsize,:)=[pop(ma,1:xp(1)) pop(pa,xp(1)+1:Nt)]; --line4
pop(2:2:popsize,:)=[pop(pa,1:xp(1)) pop(ma,xp(1)+1:Nt)]; --line5
nmut=ceil((popsize-1)*Nt*mutrate); --line6
mrow=ceil(rand(1,nmut)*(popsize-1))+1; --line 7
mcol=ceil(rand(1,nmut)*Nt); --line8
for ii=1:nmut --line9
pop(mrow(ii),mcol(ii))=abs(pop(mrow(ii),mcol(ii))-1); % toggles bits --line10
end
end
0 Comments
Answers (2)
Geoff Hayes
on 10 Dec 2018
Ifeatu - RandChooseN is not a built-in MATLAB function nor is (likely) part of any toolbox or from the File Exchage. The closest reference I could find to this function was from this site Mathematical Modeling class notes. You will need to download this file (or I suppose write it from scratch) and update your MATLAB search path to include this file so that it can be found when you reference it from other code. See What is the MATLAB Search Path? for more details.
0 Comments
Walter Roberson
on 10 Dec 2018
Your code does not contain any referece to "randcoosen". MATLAB is case sensitive, so randcoosen would not match RandCooseN. Which also would not match RandChooseN since missing h is important.
RandChooseN is not a mathworks provided routine.
It looks to me as if you might be using https://www.mathworks.com/matlabcentral/answers/327664-is-my-genetic-algorithm-result-correct or perhaps https://hrcak.srce.hr/file/253498 . The second of those includes source for its RandChooseN
1 Comment
Walter Roberson
on 23 Dec 2021
http://people.whitman.edu/~hundledr/courses/M350F14/M350/RandChooseN.m is another source
See Also
Categories
Find more on Genetic Algorithm in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!