Usage of validateattributes with 'nonzero'

3 Ansichten (letzte 30 Tage)
Dirk Twisk
Dirk Twisk am 22 Mär. 2017
Kommentiert: Adam am 22 Mär. 2017
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.

Antworten (1)

Adam
Adam am 22 Mär. 2017
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 Kommentare
Dirk Twisk
Dirk Twisk am 22 Mär. 2017
Bearbeitet: Dirk Twisk am 22 Mär. 2017
OK. My solution is to do this:
>> validateattributes(prod([0 0 1]),{'numeric'},{'nonzero'})
Expected input to be nonzero.
Adam
Adam am 22 Mär. 2017
That should certainly work fine

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Programming Utilities finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by