return value optimization when overwriting

1 回表示 (過去 30 日間)
Federico
Federico 2012 年 2 月 7 日
Consider the following scenario.
function A=frobnicate(A)
A(1)=1;
end
X=zeros(2000,2000);
X=frobnicate(X);
By inspecting variables with `format debug`, one can see that Matlab (even in R2011b) makes an unnecessary copy of the whole 2000x2000 matrix when it calls the function in the last row. Is there a way to avoid the copy and let the function work on the data "in-place"?
I know about global variables and handle objects, but I read that both are quite inefficient and I doubt that they will actually make something like the above code faster.

回答 (2 件)

Jan
Jan 2012 年 2 月 7 日
No, unfortuantely you cannot force Matlab to work inplace.

Federico
Federico 2012 年 2 月 14 日
I cannot understand how it works exactly, though, the return addresses inspected with "format debug" seem to change, but the time speedup is there.

カテゴリ

Help Center および File ExchangeIntroduction to Installation and Licensing についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by