MATLAB: I want to create a function z=f(a,b)..how can I create like this using the below code

functions

if true
a=Ns;
b=8;
if ~mod(a,b)
z=0
else
z=b-mod(a,b);
end
end

Best Answer

MATLAB documentation tells you how to make functions. Like, to make your "f" function you'd do this:
function z = f(a, b)
if ~mod(a,b)
z=0
else
z=b-mod(a,b);
end
To call it, you'd do this:
a = Ns;
b = 8;
z = f(a, b)