Search code examples
matlabfunctionfunction-handletilde

What does a function with this ~ mean? (e.g. function=f(~, x, y))


I am doing another coursera assignemnt, this time with aerial robotics. I have to program a pd controller using the matlab ode45 (ordinary diff. equation). And the file that has to contain this code gets called as follows:

pd_controller(~, s, s_des, params)

I searched around but couldn't find anthing that explain this to me and how it works.

In the main program the function is called with a time variable which I would need for my ODE:

controlhandle(t, s, s_des, params)

Where this controlhandle is the functionhandler for pd_controller.

So, what does this mean? And can I access whatever is behind ~?

Besides: I found one example, but the other around. A function, let's call it function = f(a,b) was called with f(~, b) where a and b has been declared inside the function.


Solution

  • The symbol is called a tilde, and it signifies that you are ignoring that input argument.

    See the documentation here: https://mathworks.com/help/matlab/matlab_prog/ignore-function-inputs.html

    In your case, the function controlhandle will not be passed a t variable, and probably has (should have) some check for this and perhaps a default t if none is given.


    This works the same with output arguments, for example if you want the index of a max in an array, but not the max itself, you would use

    a = [pi, 3.6, 1];
    [~, idx] = max(a); % idx = 2, we don't know what the max value is