Effacer les filtres
Effacer les filtres

multi choice validate attributes

2 vues (au cours des 30 derniers jours)
Benoit Botton
Benoit Botton le 1 Juil 2014
Commenté : Benoit Botton le 3 Juil 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

Réponse acceptée

Geoff Hayes
Geoff Hayes le 3 Juil 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 commentaire
Benoit Botton
Benoit Botton le 3 Juil 2014
thanks Geoff, wondering how I missed it!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Argument Definitions dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by