Usage of validateattributes with 'nonzero'

I am wondering whether this is a bug:
validateattributes([0 0 1],{'numeric'},{'nonzero'})
Should result in an error, but the test passes as long as at least one element of the vector is nonzero. The function documentation says otherwise.

답변 (1개)

Adam
Adam 2017년 3월 22일

0 개 추천

Which version of Matlab are you using? In R2017b:
>> validateattributes( [0 0 1], { 'numeric' }, { 'nonzero' } )
Expected input to be nonzero.
so it looks to be working fine. Maybe it is a bug in an older version though. Strangely, in all my thousands of usages of validateattributes over the years I have never actually used 'nonzero' so hadn't even realised it existed as an attribute!

댓글 수: 4

Dirk Twisk
Dirk Twisk 2017년 3월 22일
Hi Adam, I checked this in 2013b and 2015b.
Adam
Adam 2017년 3월 22일
Hmm, I don't have R2015b or earlier installed any more, but it works in R2016a. Maybe it was fixed for that version.
Dirk Twisk
Dirk Twisk 2017년 3월 22일
편집: Dirk Twisk 2017년 3월 22일
OK. My solution is to do this:
>> validateattributes(prod([0 0 1]),{'numeric'},{'nonzero'})
Expected input to be nonzero.
Adam
Adam 2017년 3월 22일
That should certainly work fine

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

카테고리

도움말 센터File Exchange에서 Programming Utilities에 대해 자세히 알아보기

태그

질문:

2017년 3월 22일

댓글:

2017년 3월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by