Ensure the syntax is what we guess

조회 수: 2 (최근 30일)
Raphael Cautain
Raphael Cautain 2012년 8월 17일
It would be nice to publish (as in Old School Languages) a syntax summary of Matlab, reflecting the exact behaviour of the interpreter.
It could help to prevent surprise from unexpected results, such as when one evaluates the expression : 5 + 1*0:10
A single transcription of the formal grammar contained in the interpreter's code would be sufficient.
Thanks.
  댓글 수: 2
Walter Roberson
Walter Roberson 2012년 8월 17일
Yes, a BNF would be good.
Walter Roberson
Walter Roberson 2012년 8월 17일
I would not call it a bug. It just reflects that ":" is a low priority operator, which is consistent. If you want to raise the priority of the ":" then use brackets.

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2012년 8월 17일
You do not have to _guess_ the details of the syntax. It is explained exhaustively in the documentation already. Your example |5 + 1*0:10| is clear after reading:
doc precedence
  댓글 수: 2
Raphael Cautain
Raphael Cautain 2012년 8월 18일
That's right, thanks. This precedence rule is very useful when we write subscripts, like in "subimg = img(x-r:x+r, y-r:y+r);" We just lost the equality of sizes between 0:10 and 1+0:10, which is really less useful and requires then to write 1+(0:10). No problem, it's just an habit.
Jan
Jan 2012년 8월 18일
Note, that X((1+0):(1+10)) will be processed faster than X(1 + (0:10)): In the 1st case the limits are checked for the marginal elements only, while in the 2nd case Matlab wastes time with boundary checks. Of course this is more important for larger index vectors.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Object Programming에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by