フィルターのクリア

Syntax error of old version ???

4 ビュー (過去 30 日間)
Mitch Martelli
Mitch Martelli 2011 年 10 月 20 日
Hi @ all
I see the last Matlab contest and I try to download the winner file...
I Run this file and I have an error in this code row : [~, board_idx] = min(SCORE);
The error is : ??? Error: File: solver.m Line: 67 Column: 3 Expression or statement is incorrect--possibly unbalanced (, {, or [.
I would like to know what is the meaning of the ~ inside the parenthesis and if this kind of sintax is only supported by the newest Matlab version . ( I use R2007b)
Thank
Best Regard
M1Tc4

採用された回答

Wayne King
Wayne King 2011 年 10 月 20 日
[~, board_idx] = min(SCORE);
The above syntax where you can suppress an output argument was not included the R2007b version.
I forget exactly when it was introduced. In R2008a or b I think.
  1 件のコメント
Wayne King
Wayne King 2011 年 10 月 20 日
sorry, I misjudged when it was introduced, it was R2009b.

サインインしてコメントする。

その他の回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2011 年 10 月 20 日
write
[ignore, board_idx] = min(SCORE);
  2 件のコメント
Mitch Martelli
Mitch Martelli 2011 年 10 月 20 日
Ok. thanks a lot. Now it works.
If I well understand if I put ~ in output or in input function argoument Matlab suppress the value? but this have sense only if a want to suppress a specific position ?
If i write a function with variable numbers of input or output this can be unsefull?
Walter Roberson
Walter Roberson 2011 年 10 月 20 日
In the 'function' line of a function, you can put a ~ for any given parameter. That tells MATLAB that you will be passing a parameter at that position but that you wish to ignore that parameter. The calling routine must pass *something* there.
This is not a mechanism for a variable number of arguments: this is a mechanism for situations where your code has internal code has evolved to no longer require one of the arguments but you do not wish to change all of the calls. It is also a mechanism useful when you have table-driven calls with a fixed calling sequence where not all of the routines being called need to pay attention to all of the arguments.
The ~ in an output position is usable only in an assignment statement, and is _not_ usable in a function definition.
Using ~ with a function that has a variable number of input arguments is just the same as above: you could only use it positionally and in a fixed input argument position.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeHistorical Contests についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by