A pointer (or reference) in Matlab
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 (2024). 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
Platform Compatibility
Windows macOS LinuxCategories
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
Version | Published | Release Notes | |
---|---|---|---|
1.0.0.0 |