0

If I have a function a that accepts 2 parameters (double) in Matlab as follows

function [x,y] = a(z)

What does the symbol "~" do when the function is called with this handle as follows

[x,~,y] = a[10]

Thanks

knedlsepp
  • 6,065
  • 3
  • 20
  • 41
Raja Sattiraju
  • 1,262
  • 1
  • 20
  • 42
  • In general, it means use the three-output version of the function, but ignore the second output argument . It's like `[x,temp,y] = a[10]`, but the variable `temp` is not even created. See [here](http://es.mathworks.com/help/matlab/matlab_prog/ignore-function-outputs.html). But in your case, you don not seem to have a three-output version of the function, so you will get an error – Luis Mendo Jan 29 '15 at 13:18
  • 1
    As with anything, try `help ~`. – horchler Jan 29 '15 at 16:03

1 Answers1

1

The "~" symbol in matlab is logical NOT. So it's basically like ignoring that output/input. For example, if I have a line of code like this:

[out1,~,out3] = function(vargin);

the second output is not kept or stored anywhere for later use. For more info, type "help ~" in the command window.

willpower2727
  • 769
  • 2
  • 8
  • 23
  • 2
    I don't think there's a conceptual link between `~` used as "logical not" and used as "ignore output". I'd rather see it as two different meanings of the same symbol – Luis Mendo Jan 29 '15 at 13:20
  • Perhaps you are right, what I should have posted was this: ">> help ~ ~ Logical not. ~A performs a logical not of input array A, and returns an array containing elements set to either logical 1 (TRUE) or logical 0 (FALSE). An element of the output array is set to 1 if A contains a zero value element at that same array location. Otherwise, that element is set to 0. B = not(A) is called for the syntax '~A' when A is an object. ~ can also be used to ignore input arguments in a function definition, and output arguments in a function call. See "help punct" – willpower2727 Jan 29 '15 at 13:24