In MATLAB, the following code returns m
and s
:
function [m,s] = stat(x)
n = length(x);
m = sum(x)/n;
s = sqrt(sum((x-m).^2/n));
end
How would I define my
stat
function in Julia?
function stat(x)
n = length(x)
m = sum(x)/n
s = sqrt(sum((x-m).^2/n))
return m, s
end
For more details, see the section entitled Multiple Return Values in the Julia documentation:
In Julia, one returns a tuple of values to simulate returning multiple values. [...]