multi choice validate attributes

3 次查看(过去 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

采纳的回答

Geoff Hayes
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 CenterFile Exchange 中查找有关 Argument Definitions 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by