|
"Max " <nikitchmPublic@gmail.com> wrote in message <hnbs6k$acj$1@fred.mathworks.com>...
> ImageAnalyst <imageanalyst@mailinator.com> wrote in message <521c53fa-84c0-446b-a7fc-f5b0a07f07a3@y11g2000yqh.googlegroups.com>...
> > Max
> > I never see a warning in my command window when my code hits a
> > "global" statement. If yours does, you can turn off warnings with the
> > warning() function.
>
> I know I can. What I'm worried about is that the message says this ability to turn local variable into global will be discontinued in the future. So I'm looking for an alternative way doing it.
==============
Are you sure you need to do this? No matter how huge your data is, as long as you never make any changes to it, you can pass it around freely to functions and MATLAB will not make any deep copies of it. Make sure you are familiar with the material here
http://blogs.mathworks.com/loren/2006/05/10/memory-management-for-functions-and-variables/
If you are making changes to your data, consider wrapping it inside a handle object. For example, using the classdef at the bottom of this post, I can do as follows
obj=refwrap;
obj.data=MyHugeData;
clear MyHugeData
I can now pass obj around to any function I like, and access and change MyHugeData through obj.data pretty much any way I like, and no deep copies of the data will ever be made.
classdef refwrap < handle
%REFWRAP - a generic handle class for arbitrary MATLAB data
%
% obj=refwrap(X)
%
%where dataInput is any MATLAB variable will result in a handle object
%obj with obj.data=X
%
%This is useful, for example, if we want to force X to be processed by
%reference in a function call, i.e.,
%
% obj=refwrap(X); clear X
% func(obj,...)
%
%would allow func() to process obj.data arbitrarily, without making a 2nd deep
%copy of X, and so that obj.data in the base workspace would feel the
%changes made by func.
properties
data;
end
methods
function obj=refwrap(dataInput)
if nargin==0, return; end
obj.data=dataInput;
end
end
end
|