Thread Subject: renaming variables

Subject: renaming variables

From: fred nerk

Date: 18 Dec, 2011 12:09:53

Message: 1 of 6

Hi

how do I rename a large array without creating a new array and
deleting the old one?

this is relevant when a data array is too large to allow 2 copies to
coexist in memory

thanks

Subject: renaming variables

From: Nasser M. Abbasi

Date: 18 Dec, 2011 13:53:43

Message: 2 of 6

On 12/18/2011 6:09 AM, fred nerk wrote:
> Hi
>
> how do I rename a large array without creating a new array and
> deleting the old one?
>
> this is relevant when a data array is too large to allow 2 copies to
> coexist in memory
>
> thanks

Simply do A=B

Matlab will NOT make a copy of B when it makes A since
B has not yet changed.

Both 'A' and 'B' point to the same data in memory.

Now if you continue from this point on to use only 'A',
and not touch 'B', then you have achived what you want.

But If you do not want 'B' hanging around, just do

clear B

right after doing A=B

Now A is your new variable name. Nothing deleted, noting
created. Use A from now on.

--Nasser

Subject: renaming variables

From: Rune Allnor

Date: 18 Dec, 2011 14:32:44

Message: 3 of 6

On 18 Des, 13:09, fred nerk <fnerk...@gmail.com> wrote:
> Hi
>
> how do I rename a large array without creating a new array and
> deleting the old one?
>
> this is relevant when a data array is too large to allow 2 copies to
> coexist in memory

Is it? Why would you want to rename?
Why can't you keep the name you alredy
use? Or start out with a better name?

Rune

Subject: renaming variables

From: Nasser M. Abbasi

Date: 18 Dec, 2011 16:16:22

Message: 4 of 6

On 12/18/2011 8:32 AM, Rune Allnor wrote:

> Or start out with a better name?
>
> Rune

Smart solution Rune, I have not thought of that :)

I think the Matlab group, for some reason, has the most
'interesting' type of programming questions than any
other group I've seen.

--Nasser

Subject: renaming variables

From: Matt J

Date: 18 Dec, 2011 18:57:08

Message: 5 of 6

fred nerk <fnerk221@gmail.com> wrote in message <0ed4c258-968b-4674-882e-eb81d6700a13@o7g2000yqk.googlegroups.com>...
> Hi
>
> how do I rename a large array without creating a new array and
> deleting the old one?
>
> this is relevant when a data array is too large to allow 2 copies to
> coexist in memory
=====================

In addition to what has already been said, make sure you're familiar with this:

http://blogs.mathworks.com/loren/2006/05/10/memory-management-for-functions-and-variables/

Subject: renaming variables

From: fnerk221@gmail.com

Date: 20 Dec, 2011 13:51:32

Message: 6 of 6

Thanks Nasser, just what I wanted to know. I knew that was how it worked on passing arguments to functions, but for some now-forgotten reason I thought that this was specific to the function-passing mechanism.

In reply to the unhelpful questions from another correspondent: what is hard to understand about the fact that processing large arrays (eg, taking up >50% of the available array memory) requires a different mindset from 'ordinary' programming? Comments like "choose another name" just show a complete lack of understanding of the problems. I am using a Win32 system. Win32 has a max of 2G for contiguous memory allocation, and the /3G switch is of little help because the 3G is not contiguous. Windows system allocation methods fragment the Matlab workspace during use in ways which cannot be fixed by packing and clearing memory, only by starting a new session. Therefore max available space for a single array in a session steadily decreases, and typically the size of the largest array which can be created on this platform is substantially < 1G. If you are working with algorithms that require a lot of random access to a single large data array then writing blocking/deblocking methods of handling the array with file i/o is highly inefficient, slow to program and slow to execute. The only sensible path is keep the large array in memory if at all possible. The Immediate problem is that you can't copy it without running out of memory. Since nearly all of my programming eventually gets scaled up to large arrays (in diverse fields: eg, testing high quality PRNGs, stitching together an arbitrary number of large image files, number theory investigations), I find that care in controlling the creation of new arrays is a key programming criterion. The algorithms HAVE to work on the one array without copying it, there just isn't room. Finally, even if there was space, consider how absurd it is NOT to use renaming in many common memory-limited situations. Processing an arbitrary selected array from a set of large arrays can all be done efficiently in the same workspace if the chosen array is simply renamed to a standard name. The alternative is to pass the chosen array to a function BUT you have to pass the (often numerous) state control variables as well, which creates a lot of unnecessary overhead, but worse is the fact that processing the array inside the function is going to create out of memory errors. Renaming the array and continuing the analysis in the same workplace is in contrast fast, efficient and logical. By the way, all of the applications that interest me involve naturally dense arrays, and sparse array storage is not an option.

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
copy on write Matt J 18 Dec, 2011 13:59:08
rssFeed for this Thread

Contact us at files@mathworks.com