Azzera filtri
Azzera filtri

Syntax error of old version ???

4 visualizzazioni (ultimi 30 giorni)
Mitch Martelli
Mitch Martelli il 20 Ott 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

Risposta accettata

Wayne King
Wayne King il 20 Ott 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 Commento
Wayne King
Wayne King il 20 Ott 2011
sorry, I misjudged when it was introduced, it was R2009b.

Accedi per commentare.

Più risposte (1)

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

Accedi per commentare.

Categorie

Scopri di più su Historical Contests in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by