-1

I have array below array 'A'

A = [9 2 9 5 6 40000];

if I use tilde (~) in below way then it gives me different output but I'm not able to understand what operation it performs.

case 1:

[~, C] = unique(A)

output:

2
4
5
1
6

case 2:

[~, ~, C] = unique(A)

output:

4
1
4
2
3
5

my question is what kind of operations "~" operator is performing on an array?

siraj pathan
  • 1,455
  • 1
  • 14
  • 31
  • 1
    Does this answer your question? [tilde character in the brackets (matlab code)](https://stackoverflow.com/questions/13913325/tilde-character-in-the-brackets-matlab-code) – Will Dec 03 '19 at 15:41
  • That is not array syntax, it's merely grouping of different output parameters, for which The MathWorks choose to use square brackets. The output parameters can be completely different from one another (type, size etc) and this will still work, whereas an array doesn't work in that case. – Adriaan Dec 04 '19 at 15:24

1 Answers1

2

In the context of output arguments, the ~ simply means “unused output”. The reason C changes in your code above is that you are requesting a different output argument defined as C in each case.

Alex Taylor
  • 1,402
  • 1
  • 9
  • 15
  • 1
    Since the ~ is usually interpreted as "not", just interpret it as "not this output". You can skip those outputs and holding the function from messing up your workspace. Since normally one orders the output in the order of which they are calculated, there won't be an improvement in terms of speed if you suppress an output. You may want to have a look at this post: https://stackoverflow.com/questions/19498911/how-to-determine-if-an-output-of-a-function-call-is-unused#19499664 and at this blog-post from matlab https://blogs.mathworks.com/loren/2019/05/21/how-to-suppress-function-output/ – max Dec 04 '19 at 07:58