I'm trying to learn MATLAB now; I tried a simple step, factorial function.
factorial.m
:
function result = factorial (m)
if m == 1
result = m;
else
result = m .* factorial(m.-1);
end
and then call it like this:
x = 2;
f = factorial (x)
but all I get is an error:
Missing variable or function.
close all closes all figures whose handles are visible. A figure handle is hidden if the HandleVisibility property is set to 'callback' or 'off' . example. close all hidden closes all figures, including figures with hidden handles.
close deletes the current figure (equivalent to close(gcf) ). close(h) deletes the figure identified by h. If h is a vector or matrix, close deletes all figures identified by h. close name deletes the figure with the specified name.
fclose('all') closes all open files. status = fclose(___) returns a status of 0 when the close operation is successful. Otherwise, it returns -1 . You can use this syntax with any of the input arguments of the previous syntaxes.
.
after the 2nd m
if
should be in a separate line from the function declaration.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With