only accept odd numbered input arguments

9 ビュー (過去 30 日間)
Ahmed Abdulla
Ahmed Abdulla 2020 年 5 月 29 日
編集済み: Adam Danz 2020 年 6 月 1 日
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 Center および File ExchangeGet 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