What test is validateattributes() using to check for attributes 'positive' or 'nonnegative' ? (possible bug)
2 views (last 30 days)
Show older comments
Naor Movshovitz
on 10 Oct 2015
Commented: Naor Movshovitz
on 12 Oct 2015
Suppose a class MyClass with overloaded operators for comparison with numeric values. In other words, I can call
obj = MyClass();
obj > 0; obj >= 0; obj < 0; obj <=0;
and get appropriate results. However, the calls
validateattributes(obj,{'MyClass'},{'positive'})
validateattributes(obj,{'MyClass'},{'nonnegative'})
always fail. Is this a bug, or is validateattributes using something other than gt, ge, lt, le calls?
Thanks, -naor (R2014b)
0 Comments
Accepted Answer
Geoff Hayes
on 12 Oct 2015
Naor - for MATLAB R2014a (on OS X 10.9.5) in order for
validateattributes(obj,{'MyClass'},{'positive'})
to pass, you need the following anonymous function to resolve to true
@(x)(isnumeric(x)||islogical(x))&&isreal(x)&&~any(x(:)<=0)
where x is the instance of your MyClass. I suspect that all you are missing is the isreal overload as you should have the isnumeric and le already. For
validateattributes(obj,{'MyClass'},{'nonnegative'})
you need the following anonymous function to resolve to true
@(x)(isnumeric(x)||islogical(x))&&isreal(x)&&~any(x(:)<0)
with the only other function that you need to overload being the lt one.
More Answers (0)
See Also
Categories
Find more on Software Development Tools in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!