I am using the MATLAB optimtool for genetic algorithm optimization.
I am opening a new script with the name 'm_0a4'FitnessFunction = @m_0b4;NumberOfVariables = 1;[x,fval] = ga(FitnessFunction, numberOfVariables);%Here I minimize the difference y
I am opening a second new script naming it 'm_0b4'function y = m_0b4(x)prompt = 'write it down';i = input(prompt) %the input valuey = x - i; % the variable I want to minimize
The functionnn m_0b4 request me for a value 'i' and I am typing the input,
The script m_0a4 of genetic algorithm calls the 'y'.
As I type the value, MATLAB keep on requesting me again for a value. When I am typing 'Enter' MATLAB brings me an error.
Assignment has more non-singleton rhs dimensions than
non-singleton subscripts
Caused by:
Failure in user-supplied fitness function evaluation.
GA cannot continue.
I cant think why MATLAB doesn't understand that I give an input (for example the number 5). Is there any idea?
Thank you in advance!
gacalls your FitnessFunction it will ask the user for an input? - BillBokeeygamust call my FitnessFunction one time. By the way I believe, it's weird that my fitness function will be requesting an input from the user many times. I say that because when I simply type for examplei = 1mygaworks well and calls the FitnessFunction one time. - panos deemacgawill work iteratively by calling the fitness function as many times as needed to be within the default tolerance from the minimum (it actually stops when two subsequent calls to the fitness function give the same result). If you definei=1you get rid of the problem by not requesting user input. Please have a look at my answer - BillBokeeyifor all the iterations. - panos deemac