How can a function have multiple return values in Julia (vs. MATLAB)?

前端 未结 1 391
渐次进展
渐次进展 2021-01-04 22:36

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         


        
相关标签:
1条回答
  • 2021-01-04 23:15

    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. [...]

    0 讨论(0)
提交回复
热议问题