Hi
my friend send to me a code that I don`t understand a line of it. The line is:
[~ , x_opt] = min(g); % g is the cost function vector
my question is that what is the meaning of "[~," in a matrix?
thanks

 Réponse acceptée

Star Strider
Star Strider le 25 Mar 2016

2 votes

The tilde ‘~’ in a function output tells MATLAB to not import that output in the calling function workspace. The min function can produce two outputs, the minimum (the first output) and the index of the first instance of the minimum value for the second. In the code you quoted, whoever wrote it was only interested in the index.

6 commentaires

hamid
hamid le 25 Mar 2016
Modifié(e) : hamid le 25 Mar 2016
Thanks Dear.
Star Strider
Star Strider le 25 Mar 2016
My pleasure.
Allan
Allan le 23 Mar 2023
Can you simplify '~' pleaase
Im just starting out in MATLAB
Star Strider
Star Strider le 23 Mar 2023
@Allan — See the documentation section on: not, ~.
Allan
Allan le 23 Mar 2023
Modifié(e) : Allan le 23 Mar 2023
Thank You Mr.Star Strider (you are a goat)
Star Strider
Star Strider le 23 Mar 2023
My pleasure!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Get Started with MATLAB dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by