only accept odd numbered input arguments

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 日

0 投票

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 件)

製品

リリース

R2019b

質問済み:

2020 年 5 月 29 日

編集済み:

2020 年 6 月 1 日

Community Treasure Hunt

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

Start Hunting!

Translated by