The only way that I can think of to do this without a memory copy would be to wrap the original data in an object that is a subclass of the handle class.
http://www.mathworks.co.uk/help/techdoc/matlab_oop/brfylzt-1.html
You can then 'copy' the handle class using normal syntax
classB=classA
..but you are only making an alias for the same data (changes to classB are reflected in classA). This is the closest thing in matlab to pointer-like semantics.
For example, create a file called myHandle
and paste the following text to define the class . .
classdef myHandle < handle
properties
data
moreData
end
methods
end
end
You can then use this just like a regular structure. From the command line do ..
>> x = myHandle
x =
myHandle handle
Properties:
data: []
moreData: []
Methods, Events, Superclasses
... we can then populate the data . . .
>> x.data = [1 2 3 4];
>> x.moreData = 'efg';
... once the original object has been populated with data, an alias of the original data can be made by typing . .
>> y = x
The interesting thing happens to x
when y
is modified, i.e.
>> y.data = [33 44 55 66];
>> disp(x)
x =
myHandle handle
Properties:
data: [33 44 55 66]
moreData: 'f'
Methods, Events, Superclasses
You can even clear one of the alias names . .
clear x
..and the data will still be available in the other handle for the data, y
. The memory is only freed when there are no more handles referring to it (when the reference count has reached zero).