xxxxxxxxxx
function f = fact(n)
f = prod(1:n);
end
xxxxxxxxxx
%%%% general syntax %%%%%%%%%%%%%
function [return parameters] = name_of_function(attributes)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
body_of_the_function
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end
xxxxxxxxxx
function cal = calculatorInMatlab()
x=input("Enter op ",'s');
n1=input("Enter a number: ");
n2=input("Enter a number: ");
switch(x)
case '+'
cal=n1+n2;
disp("sum= "+ int2str(cal));
case '-'
cal=n1-n2;
disp("sum= "+int2str(cal));
otherwise
disp("invalid");
end