1

I have an .m file in matlab named PowerMinimiser and two functions in it

function PowerMinimiser
    PowerOut = fmin(minFunction,0,100);
    display(PowerOut)
end

and

function PowerOut = minFunction(varargin)
    RunMode = 2;
    ThresholdValue = 10;
    if nargin > 0
        ThresholdValue  = varargin{1};
    end
    %Receive PowerOut value from .main file and pass in ThresholdValue and
    %RunMode values:
    [PowerOut] = main(ThresholdValue,RunMode);
end

Now what I would like to do is use the matlab fmin function so that I can find a value for the variable ThresholdValue which will give the lowest value possible for the variable PowerOut. The value for ThresholdValue is a number between 1 and 100, and is passed into a function in the main.m where a number of calculations are done and then a value for PowerOut is outputted.

Using the minFunction function I am able to receive and pass the variable fine, using the line

     [PowerOut] = main(ThresholdValue,RunMode);

but I am not sure how to use the fmin function to get the value of ThresholdValue that gives the lowest value for PowerOut. I would like the ThresholdValue value to be shown once the fmin has done the necessary calculations. How can I do this? Any help would be greatly appreciated.

Thanks

Shai
  • 111,146
  • 38
  • 238
  • 371
thomashs87
  • 59
  • 2
  • 4

1 Answers1

0

You should use function fminbnd, which replaced fmin function in newer versions of Matlab. To pass function as an argument to fminbnd use @ in front of the function name, like this:

PowerOut = fmin( @minFunction, 0, 100 );
plesiv
  • 6,935
  • 3
  • 26
  • 34