Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

MATLAB Input validation and If loop practice Write a function oneorten that acce

ID: 3788622 • Letter: M

Question

MATLAB

Input validation and If loop practice

Write a function oneorten that accepts three inputs. The function should return the value 10 if there are 3 inputs passed into the function and return the value 1 if there are not enough inputs passed into the function.

Note: test cases will not have more than three inputs

MATLAB

Input validation and If loop practice

Write a function oneorten that accepts three inputs. The function should return the value 10 if there are 3 inputs passed into the function and return the value 1 if there are not enough inputs passed into the function.

Note: test cases will not have more than three inputs

Explanation / Answer

function res = oneorten(~, ~, ~) % '~' indicates the argument is optional while calling this function
if(nargin==3) % 'nargin' gives the number inputs passed to the function while calling
  
res = 10;

end

if(nargin ~=3)
res=1;
end

end