round function fails when used in subscript index

조회 수: 2 (최근 30일)
Peter
Peter 2013년 7월 24일
i'm puzzled. the following code runs without a problem:
x=[1 2 3]
x(round(end/2))
but this:
x=3;
y=round(x/2);
x=[1 2 3]
x(round(end/2)
gives the following error: "error using round. Not enough input arguments."
so round fails only if had has been called before here. anyone who can explain this?
  댓글 수: 3
Peter
Peter 2013년 7월 24일
yes I'm sure. using MATLAB R2011b.
dpb
dpb 2013년 7월 24일
...so round fails only if had has been called before here
Doesn't really imply that's the root cause...what if the test case doesn't use end but another constant or other expression?
Since R2011b has been superceded, ir can reproduce the above, go ahead and submit a bug report to official TMW support but likely they'll tell you to upgrade.
Oh--and see if there are any patches available to you for your license.

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

채택된 답변

Jan
Jan 2013년 7월 24일
편집: Jan 2013년 7월 24일
The implicit usage of end has been affected by many reported bugs in the past:
x = [1 2 3]
x(round(end/2))
See e.g. "end"-related the bugs existing in 2011b: Bug 693663, Bug 783026, Bug 754525, Bug 666701 (this could be your problem). Therefore I suggest to avoid this in general but specify the length you want to measure explicitly:
x = [1 2 3]
x(round(length(x) / 2))
As nice side effect this is even slightly faster.
Btw., reading the list of known bugs is a good programming practice. Then you do not have to be surprised again and dig in the code to find the problems.
  댓글 수: 1
Peter
Peter 2013년 7월 25일
thanks all, avoiding the implicit usage of end indeed solves the problem. still weird to me why implicit end within a call to round only fails in this case if it has been preceded by another call to round. but no reason anymore to use implicit end so case closed.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by