Hi,
I have a function called calculateValues, which is stored in a seperate .m file, and takes two inputs ( x and a), while producing 3 outputs ( out1, out2, and out3):
[out1, out2, out3] = calculateValues(x,a);
I would now like to use MatLab's fminsearch to minimise the third output (out3) of my function calculateValues with respect to the variable x (leaving a as just a constant, i.e. not varied as part of the optimisation). Therefore I wanted to do something like the following:
out3min = fminsearch(@(x)calculateValues(x,a),x0);
However, it seems like the default output to be minimised is out1. I guess I need to force the anonymous function @(x)calculateValues(x,a) to return only out3. Does anyone have any suggestions how it can be done? Maybe a way to nest anonymous functions to achieve this?
Many Thanks
Best Answer