File Exchange

image thumbnail

A pointer (or reference) in Matlab

version 1.0 (1.29 KB) by

Get the behavior of a pointer.

1 Download

Updated

View License

Create a pointer:
o = ptr();
Do anything you want with it:
o.d.msg = 'hi';
o.d.A = randn(10);
p = o;
p.d.msg = 'hello';
disp(o.d.msg); % 'hello'
Think of '.d.' as the C language's '->' operator. Write a function that acts on it:
function DoSomething(o)
o.d.A(end,end) = 10;
end
Make sure to delete it:
delete(o);
Since o and p point to the same object, p is now invalid just like o.

Comments and Ratings (1)

Val Schmidt

Val Schmidt (view profile)

MATLAB Release
MATLAB 8.0 (R2012b)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video