2018/09/04

Matlab: Find the arguments of maxima/minima (argmax/argmin) of a vector

The argument of maximum means the index at which the vector/function values is maximized.

Example

>> a = [3 2 1 -2 7]

a =
     3     2     1    -2     7

>> [max_value, argmax] = max(a)

max_value =
     7

argmax =
     5

>> [min_value, argmin] = min(a)

min_value =
    -2

argmin =
     4

>> 

References:

Arg max (Wikipedia)
how do i find argmax? (MathWorks)

2018/09/03

Matlab: feval() - Call functions with the function name as a string input

To call any Matlab function, use feval() with the function nameas the first input string and the parameters of the function as the other remaining input arguments.

For example, for sayHello.m:

function sayHello(name)

fprintf('Hello %s!\n',name);

Results of the command line with fevel():

>> sayHello('Matlab')
Hello Matlab!
>> feval('sayHello','World')
Hello World!

Reference:

feval() - Evaluation function (MathWorks)