Syntax error of old version ???

4 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Historical Contests 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by