multi choice validate attributes

3 Ansichten (letzte 30 Tage)
Benoit Botton
Benoit Botton am 1 Jul. 2014
Kommentiert: Benoit Botton am 3 Jul. 2014
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

Akzeptierte Antwort

Geoff Hayes
Geoff Hayes am 3 Jul. 2014
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.
  1 Kommentar
Benoit Botton
Benoit Botton am 3 Jul. 2014
thanks Geoff, wondering how I missed it!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Argument Definitions finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by