only accept odd numbered input arguments

9 vues (au cours des 30 derniers jours)
Ahmed Abdulla
Ahmed Abdulla le 29 Mai 2020
Modifié(e) : Adam Danz le 1 Juin 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.

Réponse acceptée

Adam Danz
Adam Danz le 29 Mai 2020
Modifié(e) : Adam Danz le 1 Juin 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

Plus de réponses (0)

Catégories

En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by