Matlab的传值调用的效率问题

编程和算法效率

http://www.mathworks.com/support/solutions/en/data/1-15SO4/index.html?solution=1-15SO4

For MATLAB built-in data types, MATLAB always passes arguments 'by value' in the sense that any changes made to input arguments within a function are not visible to the respective variables in the caller workspace.

However, since passing huge chunks of data 'by value' is inefficient, MATLAB internally optimizes for some cases and passes by reference and only creates local copies if modifications are being made to these arguments.

function a = test(m, t)

if t > 0
if t == 0
m(1, t) = t;
end
m = subtest(m);
a = test(m, t-1) + 1;
else
a = 1;
end

function a = subtest(m)
a = m;

Q.E.D.

• 支持使用微薄、微信和QQ的账户登陆进行评论。由各自网站直接认证，不会泄露你的密码。
• 登陆后可选择分享评论到所绑定的社交网络，如微薄、人人和QQ空间。
• 评论提交后无法修改。如需修改，请删除原评论再重新提交。
• 评论支持LaTeX代码，行内公式请用$$a+b=c$$，行间公式请用$a+b=c$。公式只支持英文字符。