You are now following this Submission
- You will see updates in your followed content feed
- You may receive emails, depending on your communication preferences
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 .
General Information
- Version 1.0.0.0 (1.29 KB)
MATLAB Release Compatibility
- Compatible with any release
Platform Compatibility
- Windows
- macOS
- Linux
| Version | Published | Release Notes | Action |
|---|---|---|---|
| 1.0.0.0 |
