Asked by Yogesh Shukla
on 27 Apr 2013

for p= 4:4:population

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

[~,idx]=min(dists);

best = routes(idx,:);

what idx, ~ means??

*No products are associated with this question.*

Answer by James Tursa
on 27 Apr 2013

Edited by James Tursa
on 27 Apr 2013

Accepted answer

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

Answer by the cyclist
on 27 Apr 2013

Edited by the cyclist
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
on 27 Apr 2013

Opportunities for recent engineering grads.

## 1 Comment

## the cyclist (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/73735#comment_145803

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