multi choice validate attributes
2 次查看(过去 30 天)
显示 更早的评论
Hi,
I am trying to validate attributes for a function. one of the parameters can ba scalar or vector so i wrote:
validateattributes( offsetChange, {'numeric'}, {'scalar', 'column', 'row', 'nonempty'})
if I pass a scalar to the function, no problem. If I pass a vector, I get: Expected input number 3, offsetChange, to be a scalar.
is there a way to use validateatrributes the way I want, or do I need to revert to if statements?
thank you
Benoit
0 个评论
采纳的回答
Geoff Hayes
2014-7-3
Check the attributes section of http://www.mathworks.com/help/matlab/ref/validateattributes.html and look at
'vector' Row or column vector, or a scalar value
With just this attribute, you can replace the three in your function call and evaluate the way you want
offsetchange = 43;
validateattributes( offsetchange, {'numeric'}, {'vector','nonempty'})
offsetchange = [1 2 3];
validateattributes( offsetchange, {'numeric'}, {'vector','nonempty'})
offsetchange = [1 2 3 4 5 6]';
validateattributes( offsetchange, {'numeric'}, {'vector','nonempty'})
offsetchange = [1 2 3; 4 5 6];
validateattributes( offsetchange, {'numeric'}, {'vector','nonempty'})
Expected input to be a vector.
Only the last fails, as expected.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Argument Definitions 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!