3

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.

OmG
  • 18,337
  • 10
  • 57
  • 90
Andreas K.
  • 389
  • 4
  • 17

2 Answers2

8

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
Wolfie
  • 27,562
  • 7
  • 28
  • 55
4

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.

OmG
  • 18,337
  • 10
  • 57
  • 90