MATLAB: I’m keep having an error ‘Not enough input arguments’ for this code

2 or 3 divisible testerror

function [y] = DivisibleTest(M)
for m = 1 : length(M)
if mod(M(m),2)==0
y = ["%d is divisible by 2",m,num2str(M)];
elseif mod(M(m),3)==0
y = ["%d is divisible by 3",m,num2str(M)];
elseif mod(M(m),2)==0 && mod(M(m),3)==0
y = ["%d is divisible by 2 AND 3",m,num2str(M)];
else
y = ["%d is NOT divisible by 2 or 3",m,num2str(M)];
end
end
end

Best Answer

It looks like you have opened the function and run the code by pressing F5 key or run button in the editor. This is not the way to call a function. You need to call the function either in the command window or in the script with proper input values.
Call the function in the command window s shwon below.
M = 10 ; % your input
y = DivisibleTest(M) ;
y