Syntax error of old version ???

조회 수: 1 (최근 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 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