only accept odd numbered input arguments

9 次查看(过去 30 天)
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.

采纳的回答

Adam Danz
Adam Danz 2020-5-29
编辑:Adam Danz 2020-6-1
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by