What does the character ~ mean in these code?

Hi all, I'm confused by the sentence as following:
[~,ind] = min(dist(:));
Could you tell me what does the character "~" mean in this code?
I appreciate your answer.

1 Kommentar

Daniel Shub
Daniel Shub am 23 Mai 2012
Related question: http://www.mathworks.co.uk/matlabcentral/answers/37858-the-sign-is-not-backwards-compatible

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

the cyclist
the cyclist am 23 Mai 2012

2 Stimmen

It is a "dummy" output, meaning that even though MATLAB normally generates that output, you know that you do not need it later in your code. In your particular case, you need the second output (the index), but you don't need the first output (the value of the minimum).

3 Kommentare

Yu Zhang
Yu Zhang am 23 Mai 2012
Thank you very much for your clear explanations. I just encountered the error as following:
"Expression or statement is incorrect--possibly unbalanced (, {, or [. "
It's exactly caused by the sentence “[~,ind] = min(dist(:));"
Do you know the reason?
Thank you very much!
Walter Roberson
Walter Roberson am 23 Mai 2012
Note: older versions of MATLAB do not support this syntax. If your version of MATLAB reports an invalid operation at that point, then substitute any convenient temporary variable name for the ~ . For example,
[junk, ind] = min(dist(:));
clear junk
Yu Zhang
Yu Zhang am 23 Mai 2012
It works!!!
Thank you VERY much!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Characters and Strings finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by