A pointer (or reference) in Matlab
Version 1.0.0.0 (1.29 KB) by
Andrew
Get the behavior of a pointer.
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.
Cite As
Andrew (2026). A pointer (or reference) in Matlab (https://www.mathworks.com/matlabcentral/fileexchange/40907-a-pointer-or-reference-in-matlab), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Created with
R2012b
Compatible with any release
Platform Compatibility
Windows macOS LinuxCategories
Find more on Desktop in Help Center and MATLAB Answers
Tags
Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
| Version | Published | Release Notes | |
|---|---|---|---|
| 1.0.0.0 |
