only accept odd numbered input arguments

10 visualizaciones (últimos 30 días)
Ahmed Abdulla
Ahmed Abdulla el 29 de Mayo de 2020
Editada: Adam Danz el 1 de Jun. de 2020
I am writing a function and I would like it to only run if the input argument is odd, is there an easy to specifcy that the input must be odd.

Respuesta aceptada

Adam Danz
Adam Danz el 29 de Mayo de 2020
Editada: Adam Danz el 1 de Jun. de 2020
nargin counts the number of input arguments for a function.
mod(x,2) returns 1 when x is odd.
if mod(nargin,2)~=1
error('There must be an odd number of inputs.')
end

Más respuestas (0)

Categorías

Más información sobre Get Started with MATLAB en Help Center y File Exchange.

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by