PLEASE HELP! Trying to access one variable of a multi-output functiom

This should be an easy fix, but I cant seem to find the answer anywhere. Here's the issue...
I'm trying to use simulannealbnd (a built in matlab function) to evaluate an objective function I have written. The problem is, simulannealbnd can only accept one variable, and my objective function outputs 3 variables into an array. I am only trying to input the third output into the function, but I am unsure how to do this. (I need to use the other outputs of my function in a different part of the code, and so simply deleting them is not an option.)
Here is snippets of my code to show you what I mean:
MOSA_ObjFunc_1.m
function f = MOSA_ObjFunc_1(x)
f(1)=...;
f(2)=...;
f(3)=...;
end
Main.m
% Start with the default options
options = saoptimset;
% Modify options setting
options = saoptimset(options,'MaxIter', MaxIter_Data);
...
options = saoptimset(options,'ReannealInterval', ReannealInterval_Data);
for i=1:2500
[x,fval,exitflag,output] = simulannealbnd(@MOSA_ObjFunc_1,rand(1),lb,ub,options);
%Only need @MOSA_ObjFunc_1 to input f(3) into here
...
Should be an easy fix, but I can't find the answer anywhere!
Thanks in advance.

 Accepted Answer

third = @(x) x(3);
thirdMOSA = @(x) third(MOSA_ObjFunc_1(x));
[x,fval,exitflag,output] = simulannealbnd(thirdMOSA, rand(1), lb, ub, options);

More Answers (0)

Categories

Find more on Function Creation in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!