Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
NCTM or The Math Forum.



Re: Passing large arrays between functions
Posted:
Sep 5, 2013 1:29 PM


"IceHaven " <alanlelandchan@gmail.com> wrote in message news:l0ac61$jab$1@newscl01ah.mathworks.com... > Hi, > > I'm looking for a way to pass large arrays between functions without using > globals. I have a script that analyzes lots of data, and i want to create > a function that's sole purpose is to graph this data (and in turn > centralize what data is graphed and what isn't). > > I know that I can do this by making a ton of global arrays, but this is > obviously a dangerous solution. The other solution I can think of is > somehow passing the arrays to another workspace, then pulling that > workspace into the graphing function. I'm not sure how that would work > though. > > Is there a way to gather large arrays from different functions and scripts > without using globals? > > thanks!
Glad you don't care for the global data idea!
If you simply pass the arrays but don't alter them, a real copy is never made. However, a copy is always made to hold within plots. Since copies aren't made if the arrays aren't being updated, simply send your large arrays in as input arguments.
The documentation has a bunch of information on memory as does this blog post of mine: http://blogs.mathworks.com/loren/2006/05/10/memorymanagementforfunctionsandvariables/
 Loren
http://blogs.mathworks.com/loren



