Input to output variable copies in functions : influence on cpu
Ältere Kommentare anzeigen
Hi !
One of the advantages of Matlab is its great tolerance on variable names. Meaning you can change the size, the dimension, and even the type of a variable at any time in a script. You can also use the same name for an input and an output variable.
For readability concerns however, when you successively perform a lot of operations on it, it is common (well for me at least) to use for the output variable a different name from the input one. Example :
function var_out = complex_function(var_in)
% Lots of operations on var_in %
% ---------------------------- %
% ---------------------------- %
% ---------------------------- %
var_out = var_in;
end
% or
function var_out = complex_function(var_in)
var_out = var_in;
% Lots of operations on var_out
% ---------------------------- %
% ---------------------------- %
% ---------------------------- %
end
My question is : is is bad in terms of cpu performances to do such copies ? If yes, what is the best compromise in Matlab between code readability and cpu performance concerning variables use and copies ?
I know it looks very basic a question, but then it is as much important to me to clarify its answer.
Thank you for answer !
Best,
Nicolas
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Logical finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!