MATLAB: How to change the parameter ‘MaxFunEvals’ using the psoptimset, if the integer number to pass for this parameter are in a variable.

MATLABpatternsearchpsoptimset

I need to run the patternsearch function changing the number of maximum number of functions evaluations allowed, then I am trying to change this parameter using the psoptimset function. The number I want to pass to change this parameter is in a variable. The following error is happening.
Error using psoptimset>checkfield (line 414)
Invalid value for OPTIONS parameter MaxFunEvals: must be a positive numeric (not a string).
Error in psoptimset (line 317)
options.(Names{j,:}) = checkfield(Names{j,:},arg);
Error in roda_pattern (line 31)
options = psoptimset(
'MaxFunEvals','maxeval', 'PollMethod','GSSPositiveBasis2N');
maxeval é uma variável que guarda um inteiro positivo. Como poderia mudar esse parametro usando a variável?

Best Answer

options = psoptimset('MaxFunEvals',maxeval, 'PollMethod','GSSPositiveBasis2N');
Each time you change the value, you will need to recreate the options structure.