Syntax error of old version ???

1 visualización (últimos 30 días)
Mitch Martelli
Mitch Martelli el 20 de Oct. de 2011
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

Respuesta aceptada

Wayne King
Wayne King el 20 de Oct. de 2011
[~, 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 comentario
Wayne King
Wayne King el 20 de Oct. de 2011
sorry, I misjudged when it was introduced, it was R2009b.

Iniciar sesión para comentar.

Más respuestas (1)

Andrei Bobrov
Andrei Bobrov el 20 de Oct. de 2011
write
[ignore, board_idx] = min(SCORE);
  2 comentarios
Mitch Martelli
Mitch Martelli el 20 de Oct. de 2011
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 el 20 de Oct. de 2011
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.

Iniciar sesión para comentar.

Categorías

Más información sobre Historical Contests en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by