Ensure the syntax is what we guess
2 次查看(过去 30 天)
显示 更早的评论
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
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
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 个评论
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 Center 和 File Exchange 中查找有关 Graphics Object Programming 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!