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