1 - Optimization tool: To clarify, let's start with what most optimization solvers in MATLAB take in as inputs. They take in a decision vector X. X can be any variable you choose, but it needs to be passed into the solver as a vector.
For example, lets say you have an objective function foo that takes in x,y,z as inputs:
f = foo(x,y,z)
To use this in optimization tool, or the solvers directly at the command line, you need to recast foo to accept X as in input only. this is easy to do using function handles:
objFun = @([x,y,z]) foo(x,y,z)
which can be called as:
X = [x,y,z]; f = objFun(X)
or using a single line of input (such as in Optimization Tool)
f = objFun([x,y,z]);