## what does it mean by writing [~,idx] in code?

on 27 Apr 2013

### James Tursa (view profile)

for p= 4:4:population

dists= total_dist(rand_pair(p-3:p));

[~,idx]=min(dists);

best = routes(idx,:);

what idx, ~ means??

the cyclist

### the cyclist (view profile)

on 27 Apr 2013

Yogesh, I don't know why you posted this question four times, but I deleted the other three.

## Products

No products are associated with this question.

### James Tursa (view profile)

on 27 Apr 2013
Edited by James Tursa

### James Tursa (view profile)

on 27 Apr 2013

The ~ represents an output that is discarded. It is essentially equivalent to:

```[dummy,idx]=min(dists);
clear dummy
```

For this example, the code wants to work with the index of the minimum value, not the value itself, so the minimum value that is returned is discarded and only the index is retained.

http://www.mathworks.com/help/matlab/matlab_prog/ignore-function-outputs.html?searchHighlight=tilde

### the cyclist (view profile)

on 27 Apr 2013
Edited by the cyclist

### the cyclist (view profile)

on 27 Apr 2013

When you see

```>> [a,b,c] = function(...)
```

then a,b, and c are the output of a function. If you do not want one of the outputs of a function, then you can replace it with the ~ symbol:

```>> [a,~,c] = function(...)
```

and then b will not be output.

James Tursa

### James Tursa (view profile)

on 27 Apr 2013

To clarify, the syntax doesn't actually prevent the function from producing the output ... it just causes MATLAB to ignore the output and automatically clear it instead of assigning it to a workspace variable. So using the syntax makes your code cleaner looking but the function will still use the same resources (time & memory) to run.

#### Join the 15-year community celebration.

Play games and win prizes!

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi