MATLAB: How to pass to the objective function just the elements of a matrix that satisfy the constraints

fminconGlobal Optimization ToolboxMATLABobjective-functionoptimizationpass a variable

Hi everybody,
I'm working with fmincon function. My objective function operates on matrices and at the end it makes the std dev of such matrices. Therefore, it comes out with a number that need to be minimized through the fmincon function. Constraints work on elements of the matrices (< or > of a certain threshold). At this point I would like to know how to pass to the objective function just the values of matrices that satisfy my constrains or another method to pass to the objective function just the indexes of the values that satisfy constraints.
Thank you in advance.
N.

Best Answer

Well, extracting the elements of a matrix M that satisfy a threshold is easy
indicesLogical = M>threshold;
values = M(indicesLogical)
but the objective function needs to receive the entire matrix you are optimizing over as input. If it needs to process some elements differently than others you would index/extract them as above, but inside the objective function, not prior to it.
Related Question