memory - Is there any way to assign matrix views instead of copying matrices themselves in Matlab, like in NumPy? -
a = b(1, :)
.. copies first row of b a.
is there anyway create matrix view object, like
frb = view(b(1, :))
to able refere view of matrix ? also, make so
b(1, 3) = 123123; % set b(1, 3) 123123 illustration purposes frb(3) = 9999; % set b(1, 3) 9999 disp(b(1, 3)); % prints 9999
see numpy example that: http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.view.html
you can use pointers in matlab point same matrix without making copy. here's simple example based on code using pointers in matlab
first define class inherits handle
class, matlab's pointer class. class properties store matrix.
classdef handleobject < handle properties object=[]; % matrix end methods function obj=handleobject(receivedobject) %this constructor obj.object=receivedobject; end end end
to declare matrix , matrix view, following
m = handleobject(ones(5,5)); %the constructor passes matrix object property m_view = m; %m_view copy of pointer m.object(1,1) = 5; %change matrix changing object property display(m_view.object(1,1)) %this should display 5
you add more functions handleobject
correspond desired views.
Comments
Post a Comment