from
A pointer (or reference) in Matlab
by Andrew
Get the behavior of a pointer.
|
| ptr |
classdef ptr < handle
% A pointer.
% Examples of usage:
% 1. Define a new pointer and populate the magic field d with whatever you
% want. In this case, I populate it with a struct.
% obj = ptr();
% obj.d.foo = 1:3;
% obj.d.bar = 'hi';
% 2. Define a function that acts on it.
% function DoSomething(obj, a)
% obj.d.foo(2) = 2*obj.d.foo(2);
% end
% 3. Make sure to delete it.
% delete(obj);
% Observe that if obj = ptr(), then dereferencing follows the pattern
% obj.d.foo, which is not unlike obj->foo in C: think of ".d." as "->".
% AMB ambrad@cs.stanford.edu
properties
d;
end
end
|
|
Contact us