Hi Im trying to understand how to use nargin but am having an issue. Hopefully someone can shed some light on. I copied this function from my text book
function z = sqrtfun(x,y)if (nargin==1) z = sqrt(x);elseif (nargin==2) z = sqrt(x+y);end
Then in another script I have put together this code to call the function
clc;clear;close all;x = input('x');y = input('y');z = sqrtfun(x,y);fprintf('Answer z ::: %4.2f\n', z);
The issue i'm having is that if i leave y blank no value is displayed for z. If i enter a value for x and y i get an output value for z. I don't know why this happens??
Best Answer