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