MATLAB: How to set global options

fsolveglobalMATLABoptimset

Hello.
Im trying to set global options so I can no longer set them in my code, like this:
global options
options = optimset('Display','off');
But when i call:
function
...body...
y = fsolve(......, options)
end
matlab asks me to provide options fisrt. Like he doesnt see it. What do I do wrong? Thank you.

Best Answer

For a global variable to enter the scope of any given workspace you will have to call global var_name again. This will tell MATLAB to make that global variable accessible in that workspace. In you specific case try something like this:
global options
options = optimset('Display','off');
function
...body...
global options
y = fsolve(......, options)
end
But I will still recommend that you pass options as an argument to that function and not use the global approach.
Related Question