what does this format mean

9 ビュー (過去 30 日間)
serwan Bamerni
serwan Bamerni 2015 年 7 月 24 日
回答済み: Azzi Abdelmalek 2015 年 7 月 24 日
Hello
I found the following format in one of matlab cod
[~,best] = min(X);
can anyone tell me what is [~,best] mean and why he used bracket while min returned single value

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2015 年 7 月 24 日
[min_value,index] = min(X);
% min-value is the min value and index is its index
[~,best] = min(X);
% gives only the index

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2015 年 7 月 24 日
min() does not always return a single value. If you provide two output positions, then min() returns the minimum values in the first position, and returns the indices of the minimum values in the second position.
In the context of an assignment, ~ indicates that an output is expected in that position but that the output is to be thrown away.
[~, best] = min(X)
would then mean "output the minimums to the first position and the indices of the minimums to the second position. Throw away the results in the first position because of the ~ and assign the results in the second position to the variable named "best".
In other words the code wants to know where the minimum is but does not need to know what the value of the minimum is.

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by