multi choice validate attributes
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Benoit Botton
el 1 de Jul. de 2014
Comentada: Benoit Botton
el 3 de Jul. de 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
0 comentarios
Respuesta aceptada
Geoff Hayes
el 3 de Jul. de 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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Argument Definitions en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!