MATLAB: Renaming large variables programmatically

rename

Hello,
I would like to rename a variable programmatically, and without copying it.
I work with large audio files, so "y=x; clear x" may blow up the memory.
I would like to do this within a program instead of having to click in the Workspace.
Saving it to a binary file, clearing the variable, then reading and deleting the binary file is a bit of a hack, so I'd rather do something more elegant.
Thanx in advance!

Best Answer

Are you sure that "y=x" creates a copy? In all cases I've tested, a shared dat copy is created, which creates just about 100 bytes overhead to the header of the variable. Try this:
format debug
x = 1:100
y = x
clear('x');
The shown "pr=xyz" is the pointer to the data array. It is identical for x and y, because both point to the same data. Only this would create a deep copy of the data:
x = 1:100
y = x % x and y use the same data

y(2) = 27; % now x and y must be different
clear('x');
But:
x = 1:100
y = x % x and y use the same data
clear('x');
y(2) = 27; % y still points to the same data as x did
This means that renaming a large array works directly without any tricks as long as the original is cleared before any values are changed.
But: I cannot imagine a situation which demands for renaming a variable! It is only a name, so what might be the advantage of using another one??? If it concerns EVAL, EVALIN or ASSIGNIN: Do not use them if you want to work efficiently with large arrays! If it concerns LOAD and SAVE, there are smarter solutions by using LOAD with an output argument instead of writing directly to the workspace.