only accept odd numbered input arguments

9 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

Adam Danz
Adam Danz il 29 Mag 2020
Modificato: Adam Danz il 1 Giu 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

Più risposte (0)

Categorie

Scopri di più su Get Started with MATLAB in Help Center e File Exchange

Prodotti


Release

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by