Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 418
Andreas K. Avatar asked Apr 21 '26 23:04

Andreas K.


2 Answers

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
like image 144
Wolfie Avatar answered Apr 24 '26 22:04

Wolfie


It means you don't need pass this parameter in this function call. Also, you can use it in the output of some functions too. For example:

A = [1 4 2 2 41];
[~, B] = sort(A);

this means you don't need the second output, and you can ignore that.

In your case, when no value sent for the first parameter t, probably the function acts on a default value for t in his computation.

Also, you can find more about that in matlab documentation. I should have mentioned that this post exists as an answer, but it might be here instead.

like image 42
OmG Avatar answered Apr 24 '26 23:04

OmG



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!