Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Out of Memory

Subject: Out of Memory

From: Isaac

Date: 12 Oct, 2009 17:17:23

Message: 1 of 29

Hi all :)
my matlab routine has a "out of memory" error.
if i execute the command feature memstats i get

Physical Memory (RAM):
        In Use: 2655 MB (a5f21000)
        Free: 410 MB (19ac4000)
        Total: 3065 MB (bf9e5000)
    Page File (Swap space):
        In Use: 2981 MB (ba50c000)
        Free: 3353 MB (d19cb000)
        Total: 6334 MB (18bed7000)
    Virtual Memory (Address Space):
        In Use: 2023 MB (7e71c000)
        Free: 24 MB (018c4000)
        Total: 2047 MB (7ffe0000)

i've tried to expand virtual memory from control panel, system and so on but i receive the same error at the same point of the code with this stats:
Physical Memory (RAM):
        In Use: 2899 MB (b53cb000)
        Free: 166 MB (0a61a000)
        Total: 3065 MB (bf9e5000)
    Page File (Swap space):
        In Use: 3129 MB (c3926000)
        Free: 119837 MB (1d41dd4000)
        Total: 122966 MB (1e056fa000)
    Virtual Memory (Address Space):
        In Use: 2023 MB (7e767000)
        Free: 24 MB (01879000)
        Total: 2047 MB (7ffe0000)

even if page files is much bigger than before, matlab doesn't use it...
i've tried to read the help and the material here on mathworks but i was not able to solve the problem.
Can You please help me?
thanks you very much :)

Subject: Out of Memory

From: ImageAnalyst

Date: 12 Oct, 2009 17:24:35

Message: 2 of 29

Yes, it is possible to demand more memory than your computer can
supply.
How much are you trying to allocate? (How big are the arrays you want
to make?)

Subject: Out of Memory

From: someone

Date: 12 Oct, 2009 17:31:18

Message: 3 of 29

"Isaac " <asimov4000@hotmail.com> wrote in message <havob3$388$1@fred.mathworks.com>...
> Hi all :)
> my matlab routine has a "out of memory" error.
> if i execute the command feature memstats i get
>
> Physical Memory (RAM):
> In Use: 2655 MB (a5f21000)
> Free: 410 MB (19ac4000)
> Total: 3065 MB (bf9e5000)
> Page File (Swap space):
> In Use: 2981 MB (ba50c000)
> Free: 3353 MB (d19cb000)
> Total: 6334 MB (18bed7000)
> Virtual Memory (Address Space):
> In Use: 2023 MB (7e71c000)
> Free: 24 MB (018c4000)
> Total: 2047 MB (7ffe0000)
>
> i've tried to expand virtual memory from control panel, system and so on but i receive the same error at the same point of the code with this stats:
> Physical Memory (RAM):
> In Use: 2899 MB (b53cb000)
> Free: 166 MB (0a61a000)
> Total: 3065 MB (bf9e5000)
> Page File (Swap space):
> In Use: 3129 MB (c3926000)
> Free: 119837 MB (1d41dd4000)
> Total: 122966 MB (1e056fa000)
> Virtual Memory (Address Space):
> In Use: 2023 MB (7e767000)
> Free: 24 MB (01879000)
> Total: 2047 MB (7ffe0000)
>
> even if page files is much bigger than before, matlab doesn't use it...
> i've tried to read the help and the material here on mathworks but i was not able to solve the problem.
> Can You please help me?
> thanks you very much :)

What is your "matlab routine"?
What functions are you calling?
What size vectors/matricies are you using?

Using properly allocated for loops instead of "vectoized"
code can save memory in some cases.

Subject: Out of Memory

From: Stan Bischof

Date: 12 Oct, 2009 18:02:30

Message: 4 of 29

Are you running on a 32-bit system or using a 32-bit version
of Matlab?

If so you can add all the RAM/swap you want but you'll still
never get past the fundamental 32-bit limits ( somewhere
between 2 and 4GB depending upon exactly what you ar doing ).

I'm guessing you have 32-bit code on a 32-bit OS.
If correct the only choices are more efficient code
to use less RAM or move to 64-bits.

Stan

Subject: Out of Memory

From: Isaac

Date: 13 Oct, 2009 09:34:01

Message: 5 of 29

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <e0cb6892-ee5c-497f-8c91-4de5f4745080@j4g2000yqa.googlegroups.com>...
> Yes, it is possible to demand more memory than your computer can
> supply.
> How much are you trying to allocate? (How big are the arrays you want
> to make?)

hi :) i should allocate some matrices with about 10000 rows and 100 columns

Subject: Out of Memory

From: Pekka Kumpulainen

Date: 13 Oct, 2009 10:50:19

Message: 6 of 29

"Isaac " <asimov4000@hotmail.com> wrote in message <hb1hi9$qfr$1@fred.mathworks.com>...
> ImageAnalyst <imageanalyst@mailinator.com> wrote in message <e0cb6892-ee5c-497f-8c91-4de5f4745080@j4g2000yqa.googlegroups.com>...
> > Yes, it is possible to demand more memory than your computer can
> > supply.
> > How much are you trying to allocate? (How big are the arrays you want
> > to make?)
>
> hi :) i should allocate some matrices with about 10000 rows and 100 columns

That is only 8MB each. Have you preallocated these matrices and not growing them in a loop?

Subject: Out of Memory

From: Isaac

Date: 13 Oct, 2009 11:05:13

Message: 7 of 29

"Pekka Kumpulainen" <pekka.nospam.kumpulainen@tut.please.fi> wrote in message <hb1m1b$h2d$1@fred.mathworks.com>...
> "Isaac " <asimov4000@hotmail.com> wrote in message <hb1hi9$qfr$1@fred.mathworks.com>...
> > ImageAnalyst <imageanalyst@mailinator.com> wrote in message <e0cb6892-ee5c-497f-8c91-4de5f4745080@j4g2000yqa.googlegroups.com>...
> > > Yes, it is possible to demand more memory than your computer can
> > > supply.
> > > How much are you trying to allocate? (How big are the arrays you want
> > > to make?)
> >
> > hi :) i should allocate some matrices with about 10000 rows and 100 columns
>
> That is only 8MB each. Have you preallocated these matrices and not growing them in a loop?

i'll try to :)
thanks!

Subject: Out of Memory

From: Isaac

Date: 13 Oct, 2009 14:27:21

Message: 8 of 29

"Pekka Kumpulainen" <pekka.nospam.kumpulainen@tut.please.fi> wrote in message <hb1m1b$h2d$1@fred.mathworks.com>...
> "Isaac " <asimov4000@hotmail.com> wrote in message <hb1hi9$qfr$1@fred.mathworks.com>...
> > ImageAnalyst <imageanalyst@mailinator.com> wrote in message <e0cb6892-ee5c-497f-8c91-4de5f4745080@j4g2000yqa.googlegroups.com>...
> > > Yes, it is possible to demand more memory than your computer can
> > > supply.
> > > How much are you trying to allocate? (How big are the arrays you want
> > > to make?)
> >
> > hi :) i should allocate some matrices with about 10000 rows and 100 columns
>
> That is only 8MB each. Have you preallocated these matrices and not growing them in a loop?

it always blocks me when i have this situation:

 Physical Memory (RAM):
        In Use: 2302 MB (8fec5000)
        Free: 763 MB (2fb20000)
        Total: 3065 MB (bf9e5000)
    Page File (Swap space):
        In Use: 2666 MB (a6ad2000)
        Free: 3670 MB (e5605000)
        Total: 6336 MB (18c0d7000)
    Virtual Memory (Address Space):
        In Use: 2016 MB (7e0d0000)
        Free: 31 MB (01f10000)
        Total: 2047 MB (7ffe0000)
    Largest Contiguous Free Blocks:
         1. [at 1e4c0000] 6 MB (006b0000)
         2. [at 211df000] 5 MB (005c1000)
         3. [at 0efd0000] 2 MB (00260000)
         4. [at 1813d000] 1 MB (00103000)
         5. [at 79bb9000] 0 MB (00037000)
         6. [at 7c2cf000] 0 MB (00031000)
         7. [at 7c30f000] 0 MB (00031000)
         8. [at 794cc000] 0 MB (00024000)
         9. [at 7c01f000] 0 MB (00021000)
        10. [at 7f6d0000] 0 MB (00020000)
                                            ======= ==========
                                              16 MB (010d2000)

Subject: Out of Memory

From: Pekka Kumpulainen

Date: 14 Oct, 2009 10:32:18

Message: 9 of 29

"Isaac " <asimov4000@hotmail.com> wrote in message <hb22o9$7rk$1@fred.mathworks.com>...
> "Pekka Kumpulainen" <pekka.nospam.kumpulainen@tut.please.fi> wrote in message <hb1m1b$h2d$1@fred.mathworks.com>...
> > "Isaac " <asimov4000@hotmail.com> wrote in message <hb1hi9$qfr$1@fred.mathworks.com>...
> > > ImageAnalyst <imageanalyst@mailinator.com> wrote in message <e0cb6892-ee5c-497f-8c91-4de5f4745080@j4g2000yqa.googlegroups.com>...
> > > > Yes, it is possible to demand more memory than your computer can
> > > > supply.
> > > > How much are you trying to allocate? (How big are the arrays you want
> > > > to make?)
> > >
> > > hi :) i should allocate some matrices with about 10000 rows and 100 columns
> >
> > That is only 8MB each. Have you preallocated these matrices and not growing them in a loop?
>
> it always blocks me when i have this situation:
>
> Physical Memory (RAM):
> In Use: 2302 MB (8fec5000)
> Free: 763 MB (2fb20000)
> Total: 3065 MB (bf9e5000)
> Page File (Swap space):
> In Use: 2666 MB (a6ad2000)
> Free: 3670 MB (e5605000)
> Total: 6336 MB (18c0d7000)
> Virtual Memory (Address Space):
> In Use: 2016 MB (7e0d0000)
> Free: 31 MB (01f10000)
> Total: 2047 MB (7ffe0000)
> Largest Contiguous Free Blocks:
> 1. [at 1e4c0000] 6 MB (006b0000)
> 2. [at 211df000] 5 MB (005c1000)
> 3. [at 0efd0000] 2 MB (00260000)
> 4. [at 1813d000] 1 MB (00103000)
> 5. [at 79bb9000] 0 MB (00037000)
> 6. [at 7c2cf000] 0 MB (00031000)
> 7. [at 7c30f000] 0 MB (00031000)
> 8. [at 794cc000] 0 MB (00024000)
> 9. [at 7c01f000] 0 MB (00021000)
> 10. [at 7f6d0000] 0 MB (00020000)
> ======= ==========
> 16 MB (010d2000)

The largest contiguous block is only 6MB. So you can't create even an 8MB matrix.
Still you have total 763 MB free memory, looks like the memory is very fragmented. Sure you are not growing any arrays in loops?
Impossible to help further without any code of what you have done.

Subject: Out of Memory

From: Isaac

Date: 14 Oct, 2009 12:57:02

Message: 10 of 29

"Pekka Kumpulainen" <pekka.nospam.kumpulainen@tut.please.fi> wrote in message <hb49bi$11t$1@fred.mathworks.com>...
> "Isaac " <asimov4000@hotmail.com> wrote in message <hb22o9$7rk$1@fred.mathworks.com>...
> > "Pekka Kumpulainen" <pekka.nospam.kumpulainen@tut.please.fi> wrote in message <hb1m1b$h2d$1@fred.mathworks.com>...
> > > "Isaac " <asimov4000@hotmail.com> wrote in message <hb1hi9$qfr$1@fred.mathworks.com>...
> > > > ImageAnalyst <imageanalyst@mailinator.com> wrote in message <e0cb6892-ee5c-497f-8c91-4de5f4745080@j4g2000yqa.googlegroups.com>...
> > > > > Yes, it is possible to demand more memory than your computer can
> > > > > supply.
> > > > > How much are you trying to allocate? (How big are the arrays you want
> > > > > to make?)
> > > >
> > > > hi :) i should allocate some matrices with about 10000 rows and 100 columns
> > >
> > > That is only 8MB each. Have you preallocated these matrices and not growing them in a loop?
> >
> > it always blocks me when i have this situation:
> >
> > Physical Memory (RAM):
> > In Use: 2302 MB (8fec5000)
> > Free: 763 MB (2fb20000)
> > Total: 3065 MB (bf9e5000)
> > Page File (Swap space):
> > In Use: 2666 MB (a6ad2000)
> > Free: 3670 MB (e5605000)
> > Total: 6336 MB (18c0d7000)
> > Virtual Memory (Address Space):
> > In Use: 2016 MB (7e0d0000)
> > Free: 31 MB (01f10000)
> > Total: 2047 MB (7ffe0000)
> > Largest Contiguous Free Blocks:
> > 1. [at 1e4c0000] 6 MB (006b0000)
> > 2. [at 211df000] 5 MB (005c1000)
> > 3. [at 0efd0000] 2 MB (00260000)
> > 4. [at 1813d000] 1 MB (00103000)
> > 5. [at 79bb9000] 0 MB (00037000)
> > 6. [at 7c2cf000] 0 MB (00031000)
> > 7. [at 7c30f000] 0 MB (00031000)
> > 8. [at 794cc000] 0 MB (00024000)
> > 9. [at 7c01f000] 0 MB (00021000)
> > 10. [at 7f6d0000] 0 MB (00020000)
> > ======= ==========
> > 16 MB (010d2000)
>
> The largest contiguous block is only 6MB. So you can't create even an 8MB matrix.
> Still you have total 763 MB free memory, looks like the memory is very fragmented. Sure you are not growing any arrays in loops?
> Impossible to help further without any code of what you have done.

the routine works in this way

for i=1:300
    functionA(input...)
    functionB(input...)
end

now if i execute "feature memstats" at "low i" i have:
    Physical Memory (RAM):
        In Use: 1422 MB (58ed3000)
        Free: 1643 MB (66b12000)
        Total: 3065 MB (bf9e5000)
    Page File (Swap space):
        In Use: 2002 MB (7d233000)
        Free: 4330 MB (10eaa4000)
        Total: 6332 MB (18bcd7000)
    Virtual Memory (Address Space):
        In Use: 876 MB (36cd0000)
        Free: 1171 MB (49310000)
        Total: 2047 MB (7ffe0000)
    Largest Contiguous Free Blocks:
         1. [at 35f90000] 821 MB (33570000)
         2. [at 7c41b000] 50 MB (032d5000)
         3. [at 6fa35000] 38 MB (0260b000)
         4. [at 69db5000] 31 MB (01ffb000)
         5. [at 6c08a000] 31 MB (01f16000)
         6. [at 7a9c8000] 22 MB (01678000)
         7. [at 6e085000] 18 MB (012bb000)
         8. [at 72fb5000] 14 MB (00e7b000)
         9. [at 7211c000] 14 MB (00e14000)
        10. [at 1f630000] 13 MB (00d80000)
                                            ======= ==========
                                            1056 MB (420a3000)

at "medium i" instead i have

    Physical Memory (RAM):
        In Use: 1899 MB (76bf8000)
        Free: 1165 MB (48ded000)
        Total: 3065 MB (bf9e5000)
    Page File (Swap space):
        In Use: 2472 MB (9a8ec000)
        Free: 3859 MB (f13eb000)
        Total: 6332 MB (18bcd7000)
    Virtual Memory (Address Space):
        In Use: 1329 MB (531ed000)
        Free: 717 MB (2cdf3000)
        Total: 2047 MB (7ffe0000)
    Largest Contiguous Free Blocks:
         1. [at 52a20000] 362 MB (16ae0000)
         2. [at 7c41b000] 50 MB (032d5000)
         3. [at 6fa35000] 38 MB (0260b000)
         4. [at 69db5000] 31 MB (01ffb000)
         5. [at 6c08a000] 31 MB (01f16000)
         6. [at 7a9c8000] 22 MB (01678000)
         7. [at 6e085000] 18 MB (012bb000)
         8. [at 72fb5000] 14 MB (00e7b000)
         9. [at 7211c000] 14 MB (00e14000)
        10. [at 1f630000] 13 MB (00d80000)
                                            ======= ==========
                                             598 MB (25613000)


so memory has been occupied a lot...

but if i execute "whos" i get at "low i"
Grand total is 1288651 elements using 10152250 bytes

af "medium i"
Grand total is 1301308 elements using 10253438 bytes


so it seems that the ram is being captured by the nested functions...

Subject: Out of Memory

From: Isaac

Date: 14 Oct, 2009 16:55:21

Message: 11 of 29

"Isaac " <asimov4000@hotmail.com> wrote in message <hb4hqu$kfm$1@fred.mathworks.com>...
> "Pekka Kumpulainen" <pekka.nospam.kumpulainen@tut.please.fi> wrote in message <hb49bi$11t$1@fred.mathworks.com>...
> > "Isaac " <asimov4000@hotmail.com> wrote in message <hb22o9$7rk$1@fred.mathworks.com>...
> > > "Pekka Kumpulainen" <pekka.nospam.kumpulainen@tut.please.fi> wrote in message <hb1m1b$h2d$1@fred.mathworks.com>...
> > > > "Isaac " <asimov4000@hotmail.com> wrote in message <hb1hi9$qfr$1@fred.mathworks.com>...
> > > > > ImageAnalyst <imageanalyst@mailinator.com> wrote in message <e0cb6892-ee5c-497f-8c91-4de5f4745080@j4g2000yqa.googlegroups.com>...
> > > > > > Yes, it is possible to demand more memory than your computer can
> > > > > > supply.
> > > > > > How much are you trying to allocate? (How big are the arrays you want
> > > > > > to make?)
> > > > >
> > > > > hi :) i should allocate some matrices with about 10000 rows and 100 columns
> > > >
> > > > That is only 8MB each. Have you preallocated these matrices and not growing them in a loop?
> > >
> > > it always blocks me when i have this situation:
> > >
> > > Physical Memory (RAM):
> > > In Use: 2302 MB (8fec5000)
> > > Free: 763 MB (2fb20000)
> > > Total: 3065 MB (bf9e5000)
> > > Page File (Swap space):
> > > In Use: 2666 MB (a6ad2000)
> > > Free: 3670 MB (e5605000)
> > > Total: 6336 MB (18c0d7000)
> > > Virtual Memory (Address Space):
> > > In Use: 2016 MB (7e0d0000)
> > > Free: 31 MB (01f10000)
> > > Total: 2047 MB (7ffe0000)
> > > Largest Contiguous Free Blocks:
> > > 1. [at 1e4c0000] 6 MB (006b0000)
> > > 2. [at 211df000] 5 MB (005c1000)
> > > 3. [at 0efd0000] 2 MB (00260000)
> > > 4. [at 1813d000] 1 MB (00103000)
> > > 5. [at 79bb9000] 0 MB (00037000)
> > > 6. [at 7c2cf000] 0 MB (00031000)
> > > 7. [at 7c30f000] 0 MB (00031000)
> > > 8. [at 794cc000] 0 MB (00024000)
> > > 9. [at 7c01f000] 0 MB (00021000)
> > > 10. [at 7f6d0000] 0 MB (00020000)
> > > ======= ==========
> > > 16 MB (010d2000)
> >
> > The largest contiguous block is only 6MB. So you can't create even an 8MB matrix.
> > Still you have total 763 MB free memory, looks like the memory is very fragmented. Sure you are not growing any arrays in loops?
> > Impossible to help further without any code of what you have done.
>
> the routine works in this way
>
> for i=1:300
> functionA(input...)
> functionB(input...)
> end
>
> now if i execute "feature memstats" at "low i" i have:
> Physical Memory (RAM):
> In Use: 1422 MB (58ed3000)
> Free: 1643 MB (66b12000)
> Total: 3065 MB (bf9e5000)
> Page File (Swap space):
> In Use: 2002 MB (7d233000)
> Free: 4330 MB (10eaa4000)
> Total: 6332 MB (18bcd7000)
> Virtual Memory (Address Space):
> In Use: 876 MB (36cd0000)
> Free: 1171 MB (49310000)
> Total: 2047 MB (7ffe0000)
> Largest Contiguous Free Blocks:
> 1. [at 35f90000] 821 MB (33570000)
> 2. [at 7c41b000] 50 MB (032d5000)
> 3. [at 6fa35000] 38 MB (0260b000)
> 4. [at 69db5000] 31 MB (01ffb000)
> 5. [at 6c08a000] 31 MB (01f16000)
> 6. [at 7a9c8000] 22 MB (01678000)
> 7. [at 6e085000] 18 MB (012bb000)
> 8. [at 72fb5000] 14 MB (00e7b000)
> 9. [at 7211c000] 14 MB (00e14000)
> 10. [at 1f630000] 13 MB (00d80000)
> ======= ==========
> 1056 MB (420a3000)
>
> at "medium i" instead i have
>
> Physical Memory (RAM):
> In Use: 1899 MB (76bf8000)
> Free: 1165 MB (48ded000)
> Total: 3065 MB (bf9e5000)
> Page File (Swap space):
> In Use: 2472 MB (9a8ec000)
> Free: 3859 MB (f13eb000)
> Total: 6332 MB (18bcd7000)
> Virtual Memory (Address Space):
> In Use: 1329 MB (531ed000)
> Free: 717 MB (2cdf3000)
> Total: 2047 MB (7ffe0000)
> Largest Contiguous Free Blocks:
> 1. [at 52a20000] 362 MB (16ae0000)
> 2. [at 7c41b000] 50 MB (032d5000)
> 3. [at 6fa35000] 38 MB (0260b000)
> 4. [at 69db5000] 31 MB (01ffb000)
> 5. [at 6c08a000] 31 MB (01f16000)
> 6. [at 7a9c8000] 22 MB (01678000)
> 7. [at 6e085000] 18 MB (012bb000)
> 8. [at 72fb5000] 14 MB (00e7b000)
> 9. [at 7211c000] 14 MB (00e14000)
> 10. [at 1f630000] 13 MB (00d80000)
> ======= ==========
> 598 MB (25613000)
>
>
> so memory has been occupied a lot...
>
> but if i execute "whos" i get at "low i"
> Grand total is 1288651 elements using 10152250 bytes
>
> af "medium i"
> Grand total is 1301308 elements using 10253438 bytes
>
>
> so it seems that the ram is being captured by the nested functions...

with "low i" i wanted to say i= 1...10
"medium i" i = about 50
:)

the cycle, for better explanation, is like:

M=matrix(100,1000);
for j=1:100
     functionA(M(j,:))
     functionB(M(j,:))
end

Subject: Out of Memory

From: Pekka Kumpulainen

Date: 15 Oct, 2009 07:22:02

Message: 12 of 29

"Isaac " <asimov4000@hotmail.com> wrote in message <hb4vpp$am0$1@fred.mathworks.com>...

> with "low i" i wanted to say i= 1...10
> "medium i" i = about 50
> :)
>
> the cycle, for better explanation, is like:
>
> M=matrix(100,1000);
> for j=1:100
> functionA(M(j,:))
> functionB(M(j,:))
> end

Beats me...
In this example those functions don't return any variables. The memory used by them internally should be freed as soon as they are executed. So after this code there should be about the same amount of free memory as before.
Unless you poof variables to the workspace in those functions by evalin or assignin.

Subject: Out of Memory

From: Isaac

Date: 15 Oct, 2009 08:13:25

Message: 13 of 29

"Pekka Kumpulainen" <pekka.nospam.kumpulainen@tut.please.fi> wrote in message <hb6iiq$c9a$1@fred.mathworks.com>...
> "Isaac " <asimov4000@hotmail.com> wrote in message <hb4vpp$am0$1@fred.mathworks.com>...
>
> > with "low i" i wanted to say i= 1...10
> > "medium i" i = about 50
> > :)
> >
> > the cycle, for better explanation, is like:
> >
> > M=matrix(100,1000);
> > for j=1:100
> > functionA(M(j,:))
> > functionB(M(j,:))
> > end
>
> Beats me...
> In this example those functions don't return any variables. The memory used by them internally should be freed as soon as they are executed. So after this code there should be about the same amount of free memory as before.
> Unless you poof variables to the workspace in those functions by evalin or assignin.

i am sorry, You are right. it is something like that:

M=matrix(100,1000);
for j=1:100
a=functionA(M(j,:))
b(j)=functionB(M(j,:))
end

it seems the execution of theese functions destroy free memory :(

what do You mean with "Unless you poof variables to the workspace in those functions by evalin or assignin"?

thanks :)

Subject: Out of Memory

From: Isaac

Date: 15 Oct, 2009 11:18:06

Message: 14 of 29

could all depend by the fact that MATLAB has no automatic garbage collection mechanism and so the execution of internal functions destroy memory?

Subject: Out of Memory

From: Pekka Kumpulainen

Date: 15 Oct, 2009 12:50:21

Message: 15 of 29

"Isaac " <asimov4000@hotmail.com> wrote in message <hb6lj5$rlt$1@fred.mathworks.com>...
> "Pekka Kumpulainen" <pekka.nospam.kumpulainen@tut.please.fi> wrote in message <hb6iiq$c9a$1@fred.mathworks.com>...
> > "Isaac " <asimov4000@hotmail.com> wrote in message <hb4vpp$am0$1@fred.mathworks.com>...
> >
> > > with "low i" i wanted to say i= 1...10
> > > "medium i" i = about 50
> > > :)
> > >
> > > the cycle, for better explanation, is like:
> > >
> > > M=matrix(100,1000);
> > > for j=1:100
> > > functionA(M(j,:))
> > > functionB(M(j,:))
> > > end
> >
> > Beats me...
> > In this example those functions don't return any variables. The memory used by them internally should be freed as soon as they are executed. So after this code there should be about the same amount of free memory as before.
> > Unless you poof variables to the workspace in those functions by evalin or assignin.
>
> i am sorry, You are right. it is something like that:
>
> M=matrix(100,1000);
> for j=1:100
> a=functionA(M(j,:))
> b(j)=functionB(M(j,:))
> end
>
> it seems the execution of theese functions destroy free memory :(
>
> what do You mean with "Unless you poof variables to the workspace in those functions by evalin or assignin"?
>
> thanks :)

In that piece of code a will be overwritten in each loop, shouldn't harm much. Except that it will possibly be written in a new location in each loop fragmenting memory.
If it is the same size in every loop, you could preallocate and assign using
a(1:end) = function(...
Not officially documented, but at the moment that keeps the final variable in same location.
b is growing inside loop, which is "strictly forbidden" in MATLAB. M-lint should warn you about that, depending on the version you use. From what you show, it seems to be a scalar each time?
Preallocate before the loop: b = zeros(100,1);

You can read about evalin and assignin in the docs. But, in short, don't use them.

Subject: Out of Memory

From: Isaac

Date: 15 Oct, 2009 13:20:24

Message: 16 of 29

"Pekka Kumpulainen" <pekka.nospam.kumpulainen@tut.please.fi> wrote in message <hb75qd$r14$1@fred.mathworks.com>...
> "Isaac " <asimov4000@hotmail.com> wrote in message <hb6lj5$rlt$1@fred.mathworks.com>...
> > "Pekka Kumpulainen" <pekka.nospam.kumpulainen@tut.please.fi> wrote in message <hb6iiq$c9a$1@fred.mathworks.com>...
> > > "Isaac " <asimov4000@hotmail.com> wrote in message <hb4vpp$am0$1@fred.mathworks.com>...
> > >
> > > > with "low i" i wanted to say i= 1...10
> > > > "medium i" i = about 50
> > > > :)
> > > >
> > > > the cycle, for better explanation, is like:
> > > >
> > > > M=matrix(100,1000);
> > > > for j=1:100
> > > > functionA(M(j,:))
> > > > functionB(M(j,:))
> > > > end
> > >
> > > Beats me...
> > > In this example those functions don't return any variables. The memory used by them internally should be freed as soon as they are executed. So after this code there should be about the same amount of free memory as before.
> > > Unless you poof variables to the workspace in those functions by evalin or assignin.
> >
> > i am sorry, You are right. it is something like that:
> >
> > M=matrix(100,1000);
> > for j=1:100
> > a=functionA(M(j,:))
> > b(j)=functionB(M(j,:))
> > end
> >
> > it seems the execution of theese functions destroy free memory :(
> >
> > what do You mean with "Unless you poof variables to the workspace in those functions by evalin or assignin"?
> >
> > thanks :)
>
> In that piece of code a will be overwritten in each loop, shouldn't harm much. Except that it will possibly be written in a new location in each loop fragmenting memory.
> If it is the same size in every loop, you could preallocate and assign using
> a(1:end) = function(...
> Not officially documented, but at the moment that keeps the final variable in same location.
> b is growing inside loop, which is "strictly forbidden" in MATLAB. M-lint should warn you about that, depending on the version you use. From what you show, it seems to be a scalar each time?
> Preallocate before the loop: b = zeros(100,1);
>
> You can read about evalin and assignin in the docs. But, in short, don't use them.


yes i use preallocation... but it does not affect i think...
it's more like the question we can read in this thread:
http://www.mathworks.com/matlabcentral/newsreader/view_thread/214717#575442

the use itself of the functions destroy memory... because of fragmentation???
but i can't understand a thing:
in my case it's the total amount of virtual memory which goes down with the execution of the sub functions... it's not a framentation... :(

i don't know if i am explaining well... but the "mistake" is that SOME VIRTUAL MEMORY IS DESTROYED WITHOUT CREATING NEW VARIABLES OR INCREMENTING OLD ONES...

Subject: Out of Memory

From: Jan Simon

Date: 15 Oct, 2009 15:37:18

Message: 17 of 29

Dear Isaac!

> M=matrix(100,1000);
> for j=1:100
> a = functionA(M(j,:))
> b(j) = functionB(M(j,:))
> end
>
> it seems the execution of theese functions destroy free memory :(

Since these functions disturb your memory, it would be helpful to show us functionA and functionB ...

Kind regards, Jan

Subject: Out of Memory

From: Isaac

Date: 16 Oct, 2009 08:30:20

Message: 18 of 29

"Jan Simon" <matlab.THIS_YEAR@nMINUSsimon.de> wrote in message <hb7fje$d2q$1@fred.mathworks.com>...
> Dear Isaac!
>
> > M=matrix(100,1000);
> > for j=1:100
> > a = functionA(M(j,:))
> > b(j) = functionB(M(j,:))
> > end
> >
> > it seems the execution of theese functions destroy free memory :(
>
> Since these functions disturb your memory, it would be helpful to show us functionA and functionB ...
>
> Kind regards, Jan

you are right :)

the function i invoke in the cycle is:



function [selezioneavvenuta,vettoreesposizione,beta,numerocostituentsscelti] = modello_selezione(Matricebmk,Matricionaserie,esposizionedlongassegnata,numrapportominimodausare,numeromesirapportodausare,numerogiornirapportodausare,barrierarischiodausare,numeromesirischiodausare,tiposelezionedausare,moltiplicocorrelazionedausare,barrieracorrelazionedausare,numeromesibetadausare,tipomesibetadausare,numeromassimoselezionatidausare,pesomassimodausare)

datainizio=datenum('01/01/2000');
datafine=datenum('01/01/2010');

sizedausare=size(Matricionaserie);
numerocostituents=sizedausare(1)-1;

Matricebmkw=seriesettimanale(Matricebmk);


vettoreesposizione=zeros(1,numerocostituents);
vettorepunteggiobase=zeros(1,numerocostituents);
correlazione=zeros(1,numerocostituents);
beta=zeros(1,numerocostituents);
matricionarapporti=zeros(1,numerocostituents);


perfrapportobmk=rendimentoa(Matricebmk,0,numeromesirapportodausare,numerogiornirapportodausare);
deviazionerapportobmk = deviazionea(Matricebmk,0,numeromesirapportodausare,numerogiornirapportodausare,datainizio,datafine);
rapportobmk=perfrapportobmk/deviazionerapportobmk;
for j=1:numerocostituents
    Matriceserie=[Matricionaserie(1,:); Matricionaserie(1+j,:)];
    perfrapporto=rendimentoa(Matriceserie,0,numeromesirapportodausare,numerogiornirapportodausare);
    deviazionerapporto = deviazionea(Matriceserie,0,numeromesirapportodausare,numerogiornirapportodausare,datainizio,datafine);
    matricionarapporti(1,j)=perfrapporto/deviazionerapporto;
end
numrapporto=0;
for j=1:numerocostituents
    if matricionarapporti(1,j)>rapportobmk
        numrapporto=numrapporto+1;
    end
end


if numrapportominimodausare==0 || numrapporto>numrapportominimodausare
    
    if barrierarischiodausare>0
        deviazionerischiobmk = deviazionea(Matricebmk,0,numeromesirischiodausare,0,datainizio,datafine);
        for j=1:numerocostituents
            Matriceserie=[Matricionaserie(1,:); Matricionaserie(1+j,:)];
            deviazionerischiofasecostituents(1,j) = deviazionea(Matriceserie,0,numeromesirischiodausare,0,datainizio,datafine);
        end
    end
    
    for j=1:numerocostituents
        
        Matriceserie=[Matricionaserie(1,:); Matricionaserie(1+j,:)];
        Matriceseriew=seriesettimanale(Matriceserie);

        if tiposelezionedausare==1
            [alphaa1m, betaa1m, r2a1m]=regressionea(Matriceserie,Matricebmk,0,1,0,datainizio,datafine);
            vettorepunteggiobase(1,j)=alphaa1m;
        elseif tiposelezionedausare==2
            [alphaa1m, betaa1m, r2a1m]=regressionea(Matriceserie,Matricebmk,0,1,0,datainizio,datafine);
            [alphaa3m, betaa3m, r2a3m]=regressionea(Matriceserie,Matricebmk,0,3,0,datainizio,datafine);
            [alphaa6m, betaa6m, r2a6m]=regressionea(Matriceserie,Matricebmk,0,6,0,datainizio,datafine);
            vettorepunteggiobase(1,j)=alphaa1m+alphaa3m+alphaa6m;
        elseif tiposelezionedausare==3
            [alphawa3m, betawa3m, r2wa3m]=regressionea(Matriceseriew,Matricebmkw,0,3,0,datainizio,datafine);
            vettorepunteggiobase(1,j)=alphawa3m;
        elseif tiposelezionedausare==4
            [alphawa3m, betawa3m, r2wa3m]=regressionea(Matriceseriew,Matricebmkw,0,3,0,datainizio,datafine);
            [alphawa6m, betawa6m, r2wa6m]=regressionea(Matriceseriew,Matricebmkw,0,6,0,datainizio,datafine);
            [alphawa1y, betawa1y, r2wa1y]=regressionea(Matriceseriew,Matricebmkw,1,0,0,datainizio,datafine);
            vettorepunteggiobase(1,j)=alphawa3m+alphawa6m+alphawa1y;
        elseif tiposelezionedausare==5
            [rapportopositivo, rapportonegativo, rapportototale]=rapportoperformancea(Matriceserie,Matricebmk,0,1,0,datainizio,datafine);
            vettorepunteggiobase(1,j)=rapportototale;
        end

        if tipomesibetadausare==1
            correlazione(1,j) = correlazionea(Matriceserie,Matricebmk,0,numeromesibetadausare,0,datainizio,datafine);
            [nn, beta(1,j), nn2] = regressionea(Matriceserie,Matricebmk,0,numeromesibetadausare,0,datainizio,datafine);
        elseif tipomesibetadausare==2
            correlazione(1,j) = correlazionea(Matriceseriew,Matricebmkw,0,numeromesibetadausare,0,datainizio,datafine);
            [nn, beta(1,j), nn2] = regressionea(Matriceseriew,Matricebmkw,0,numeromesibetadausare,0,datainizio,datafine);
        end
        
        vettorepunteggio=vettorepunteggiobase.*(beta>0);

    end
    
    if barrieracorrelazionedausare>0
        vettorepunteggio=vettorepunteggio.*(correlazione>barrieracorrelazionedausare);
    end
    
    if moltiplicocorrelazionedausare>0
        vettorepunteggio=vettorepunteggio.*correlazione.*(correlazione>0);
    end

    if barrierarischiodausare>0
        vettorebooleanorischio=zeros(1,numerocostituents);
        for j=1:numerocostituents
            if deviazionerischiofasecostituents(1,j)<deviazionerischiobmk*barrierarischiodausare
                vettorebooleanorischio(1,j)=1;
            end
        end
        vettorepunteggio2(1,:)=vettorepunteggio(1,:).*vettorebooleanorischio(1,:);
        passati=0;
        for j=1:numerocostituents
            if vettorepunteggio2(1,j)>0
                passati=passati+1;
            end
        end
        vettorepunteggio(1,:)=vettorepunteggio2(1,:);
    end
    
    presi=0;
    for j=1:numerocostituents
        if vettorepunteggio(1,j)>0
            presi=presi+1;
        end
    end
    numerocostituentsscelti=min(presi,numeromassimoselezionatidausare);
    
    if numerocostituentsscelti>0
        selezioneavvenuta=1;
        for j=1:numerocostituents
            if isnan(vettorepunteggio(1,j))==1
                vettorepunteggio(1,j)=-100;
            end
        end
        [a,ordinecostituents(1,:)]=sort(vettorepunteggio(1,:),'descend');
        sommabeta=0;
        for k=1:numerocostituentsscelti
            sommabeta=sommabeta+beta(1,ordinecostituents(1,k));
        end
        pesoassegnato=esposizionedlongassegnata/sommabeta;
        while pesomassimodausare>0 && pesoassegnato>pesomassimodausare && numerocostituentsscelti<presi
            numerocostituentsscelti=numerocostituentsscelti+1;
            sommabeta=0;
            for k=1:numerocostituentsscelti
                sommabeta=sommabeta+beta(1,ordinecostituents(1,k));
            end
            pesoassegnato=esposizionedlongassegnata/sommabeta;
        end
        
        for k=1:numerocostituentsscelti
            vettoreesposizione(1,ordinecostituents(1,k))=pesoassegnato;
        end
    else
        selezioneavvenuta=0;
    end
    
else
    selezioneavvenuta=0;
    numerocostituentsscelti=0;
    for j=1:numerocostituents

        Matriceserie=[Matricionaserie(1,:); Matricionaserie(1+j,:)];
        Matriceseriew=seriesettimanale(Matriceserie);

        if tiposelezionedausare==1
            [alphaa1m, betaa1m, r2a1m]=regressionea(Matriceserie,Matricebmk,0,1,0,datainizio,datafine);
            vettorepunteggiobase(1,j)=alphaa1m;
        elseif tiposelezionedausare==2
            [alphaa1m, betaa1m, r2a1m]=regressionea(Matriceserie,Matricebmk,0,1,0,datainizio,datafine);
            [alphaa3m, betaa3m, r2a3m]=regressionea(Matriceserie,Matricebmk,0,3,0,datainizio,datafine);
            [alphaa6m, betaa6m, r2a6m]=regressionea(Matriceserie,Matricebmk,0,6,0,datainizio,datafine);
            vettorepunteggiobase(1,j)=alphaa1m+alphaa3m+alphaa6m;
        elseif tiposelezionedausare==3
            [alphawa3m, betawa3m, r2wa3m]=regressionea(Matriceseriew,Matricebmkw,0,3,0,datainizio,datafine);
            vettorepunteggiobase(1,j)=alphawa3m;
        elseif tiposelezionedausare==4
            [alphawa3m, betawa3m, r2wa3m]=regressionea(Matriceseriew,Matricebmkw,0,3,0,datainizio,datafine);
            [alphawa6m, betawa6m, r2wa6m]=regressionea(Matriceseriew,Matricebmkw,0,6,0,datainizio,datafine);
            [alphawa1y, betawa1y, r2wa1y]=regressionea(Matriceseriew,Matricebmkw,1,0,0,datainizio,datafine);
            vettorepunteggiobase(1,j)=alphawa3m+alphawa6m+alphawa1y;
        elseif tiposelezionedausare==5
            [rapportopositivo, rapportonegativo, rapportototale]=rapportoperformancea(Matriceserie,Matricebmk,0,1,0,datainizio,datafine);
            vettorepunteggiobase(1,j)=rapportototale;
        end

        if tipomesibetadausare==1
            correlazione(1,j) = correlazionea(Matriceserie,Matricebmk,0,numeromesibetadausare,0,datainizio,datafine);
            [nn, beta(1,j), nn2] = regressionea(Matriceserie,Matricebmk,0,numeromesibetadausare,0,datainizio,datafine);
        elseif tipomesibetadausare==2
            correlazione(1,j) = correlazionea(Matriceseriew,Matricebmkw,0,numeromesibetadausare,0,datainizio,datafine);
            [nn, beta(1,j), nn2] = regressionea(Matriceseriew,Matricebmkw,0,numeromesibetadausare,0,datainizio,datafine);
        end

    end
end

------------------------------------------------------------------------------------

the subfunction "regressionea" is

function [alphaa, betaa, r2a]=regressionea(Matriceserie,Matricebmk,annifa,mesifa,giornifa,datainizio,datafine)

Matricedate=datevec(Matriceserie(1,:));
ultimoanno=Matricedate(end,1);
ultimomese=Matricedate(end,2);
ultimogiorno=Matricedate(end,3);

vettoreoggi=[ultimoanno, ultimomese, ultimogiorno];

numerodate=size(Matriceserie);
numerodate=numerodate(2);

giornoriferimento=trovagiorno(datenum(vettoreoggi),annifa,mesifa,giornifa);

i=numerodate;

while Matriceserie(1,i)>giornoriferimento && Matriceserie(1,i)>datainizio & i>1
   i=i-1;
end

j=1;

while Matriceserie(1,j)<datafine && j<numerodate
   j=j+1;
end


datedariferimento=Matriceserie(1,i:j);
valoridariferimento=Matriceserie(2,i:j);
valoribmkdariferimento=Matricebmk(2,i:j);

[alphaa, betaa, r2a]=regressione(valoridariferimento,valoribmkdariferimento);

----------------------------------------------------------------------------------

the subfunction "regressione" is

function [alpha, beta, r2]=regressione(serie,seriebmk)

try

n=size(serie);

if n(1)==1
    serie=serie';
    seriebmk=seriebmk';
    n=n(2);
else
    n=n(1);
end

rendimentiserie=zeros(n-1,1);
rendimentiseriebmk=zeros(n-1,1);

rendimentiserie=serie(2:end,1)./serie(1:end-1,1)-1;
rendimentiseriebmk=seriebmk(2:end,1)./seriebmk(1:end-1,1)-1;

regress(rendimentiserie,[rendimentiseriebmk ones(n-1,1)]);

[B,BINT,R,RINT,STATS] = regress(rendimentiserie,[rendimentiseriebmk ones(n-1,1)]);

alpha=B(2);
beta=B(1);
r2=STATS(1);

catch
    
alpha=0;
beta=0;
r2=0;

end

Subject: Out of Memory

From: Jan Simon

Date: 16 Oct, 2009 09:19:05

Message: 19 of 29

Dear Isaac!

I love your coding style. The names of the variables are tiny stories and the efficiency of the abbrev. engl. style is overestimated! I'm not kidding. We sit a remarkable part of the day in front of our dull computers and try to understand how the variables PrevXMat and GenVarScl_m interfere. Our brain is restructured until it matchs the scrap we are feeding it with ("learning").

> regress(rendimentiserie,[rendimentiseriebmk ones(n-1,1)]);
>
> [B,BINT,R,RINT,STATS] = regress(rendimentiserie,[rendimentiseriebmk ones(n-1,1)]);

What is REGRESS and what happens if it is called one time without and the next time with outputs?

Kind regards, Jan

Subject: Out of Memory

From: Isaac

Date: 16 Oct, 2009 13:21:18

Message: 20 of 29

"Jan Simon" <matlab.THIS_YEAR@nMINUSsimon.de> wrote in message <hb9dq9$en6$1@fred.mathworks.com>...
> Dear Isaac!
>
> I love your coding style. The names of the variables are tiny stories and the efficiency of the abbrev. engl. style is overestimated! I'm not kidding. We sit a remarkable part of the day in front of our dull computers and try to understand how the variables PrevXMat and GenVarScl_m interfere. Our brain is restructured until it matchs the scrap we are feeding it with ("learning").
>
> > regress(rendimentiserie,[rendimentiseriebmk ones(n-1,1)]);
> >
> > [B,BINT,R,RINT,STATS] = regress(rendimentiserie,[rendimentiseriebmk ones(n-1,1)]);
>
> What is REGRESS and what happens if it is called one time without and the next time with outputs?
>
> Kind regards, Jan

hi Jan, are u sure you are not kidding? :D
anyway "REGRESS" is a matlab function which makes linear regression, you can see it here:

http://www.mathworks.com/access/helpdesk/help/toolbox/stats/index.html?/access/helpdesk/help/toolbox/stats/regress.html&http://www.google.it/search?hl=it&source=hp&q=matlab+help+regress&btnG=Cerca+con+Google&meta=&aq=f&oq=

i don't understand your question "what happens if it is called one time without and the next time with outputs?", can u explain me what you wanted to mean?

thanks :)

Subject: Out of Memory

From: Jan Simon

Date: 16 Oct, 2009 16:15:20

Message: 21 of 29

Dear Isaac!

> anyway "REGRESS" is a matlab function which makes linear regression, you can see it here:
>
> http://www.mathworks.com/access/helpdesk/help/toolbox/stats/index.html?/access/helpdesk/help/toolbox/stats/regress.html&http://www.google.it/search?hl=it&source=hp&q=matlab+help+regress&btnG=Cerca+con+Google&meta=&aq=f&oq=
>
> i don't understand your question "what happens if it is called one time without and the next time with outputs?", can u explain me what you wanted to mean?

In the source you've posted, REGRESS is called without output arguments and a few lines later with outputs. It was just a guess, that REGRESS was a user defined MEX function, which does not correctly handle calls with missing outputs and looses the memory there.
Nevertheless, calling REGRESS without outputs is not needed, is it?

I'll take another look on your code, but it is a lot of characters...

Kind regards, Jan

Subject: Out of Memory

From: Isaac

Date: 17 Oct, 2009 11:45:07

Message: 22 of 29

"Jan Simon" <matlab.THIS_YEAR@nMINUSsimon.de> wrote in message <hba66o$4k7$1@fred.mathworks.com>...
> Dear Isaac!
>
> > anyway "REGRESS" is a matlab function which makes linear regression, you can see it here:
> >
> > http://www.mathworks.com/access/helpdesk/help/toolbox/stats/index.html?/access/helpdesk/help/toolbox/stats/regress.html&http://www.google.it/search?hl=it&source=hp&q=matlab+help+regress&btnG=Cerca+con+Google&meta=&aq=f&oq=
> >
> > i don't understand your question "what happens if it is called one time without and the next time with outputs?", can u explain me what you wanted to mean?
>
> In the source you've posted, REGRESS is called without output arguments and a few lines later with outputs. It was just a guess, that REGRESS was a user defined MEX function, which does not correctly handle calls with missing outputs and looses the memory there.
> Nevertheless, calling REGRESS without outputs is not needed, is it?
>
> I'll take another look on your code, but it is a lot of characters...
>
> Kind regards, Jan

You are right!!! it's a mistake :D i must delete that row (the one without output) !!! :)

Subject: Out of Memory

From: Oleg Komarov

Date: 17 Oct, 2009 18:34:03

Message: 23 of 29

"Isaac " <asimov4000@hotmail.com> wrote in message <hbcao3$isg$1@fred.mathworks.com>...
> "Jan Simon" <matlab.THIS_YEAR@nMINUSsimon.de> wrote in message <hba66o$4k7$1@fred.mathworks.com>...
> > Dear Isaac!
> >
> > > anyway "REGRESS" is a matlab function which makes linear regression, you can see it here:
> > >
> > > http://www.mathworks.com/access/helpdesk/help/toolbox/stats/index.html?/access/helpdesk/help/toolbox/stats/regress.html&http://www.google.it/search?hl=it&source=hp&q=matlab+help+regress&btnG=Cerca+con+Google&meta=&aq=f&oq=
> > >
> > > i don't understand your question "what happens if it is called one time without and the next time with outputs?", can u explain me what you wanted to mean?
> >
> > In the source you've posted, REGRESS is called without output arguments and a few lines later with outputs. It was just a guess, that REGRESS was a user defined MEX function, which does not correctly handle calls with missing outputs and looses the memory there.
> > Nevertheless, calling REGRESS without outputs is not needed, is it?
> >
> > I'll take another look on your code, but it is a lot of characters...
> >
> > Kind regards, Jan
>
> You are right!!! it's a mistake :D i must delete that row (the one without output) !!! :)

I noticed u use a function called "correlazionea". If u are calculating correlation coefficients with corrcoef, my personal suggestion is to loop the corrcoef through pairs of time series instead of calculating it at once...
Past experience taught me that is faster and avoids out of mem problems.

Subject: Out of Memory

From: Isaac

Date: 19 Oct, 2009 09:00:19

Message: 24 of 29

"Oleg Komarov" <oleg.komarov@hotmail.it> wrote in message <hbd2mr$t98$1@fred.mathworks.com>...
> "Isaac " <asimov4000@hotmail.com> wrote in message <hbcao3$isg$1@fred.mathworks.com>...
> > "Jan Simon" <matlab.THIS_YEAR@nMINUSsimon.de> wrote in message <hba66o$4k7$1@fred.mathworks.com>...
> > > Dear Isaac!
> > >
> > > > anyway "REGRESS" is a matlab function which makes linear regression, you can see it here:
> > > >
> > > > http://www.mathworks.com/access/helpdesk/help/toolbox/stats/index.html?/access/helpdesk/help/toolbox/stats/regress.html&http://www.google.it/search?hl=it&source=hp&q=matlab+help+regress&btnG=Cerca+con+Google&meta=&aq=f&oq=
> > > >
> > > > i don't understand your question "what happens if it is called one time without and the next time with outputs?", can u explain me what you wanted to mean?
> > >
> > > In the source you've posted, REGRESS is called without output arguments and a few lines later with outputs. It was just a guess, that REGRESS was a user defined MEX function, which does not correctly handle calls with missing outputs and looses the memory there.
> > > Nevertheless, calling REGRESS without outputs is not needed, is it?
> > >
> > > I'll take another look on your code, but it is a lot of characters...
> > >
> > > Kind regards, Jan
> >
> > You are right!!! it's a mistake :D i must delete that row (the one without output) !!! :)
>
> I noticed u use a function called "correlazionea". If u are calculating correlation coefficients with corrcoef, my personal suggestion is to loop the corrcoef through pairs of time series instead of calculating it at once...
> Past experience taught me that is faster and avoids out of mem problems.


thanks but i use only CORR :)

Subject: Out of Memory

From: Isaac

Date: 22 Oct, 2009 10:26:04

Message: 25 of 29

no idea about all this memory go out? :(

Subject: Out of Memory

From: Jan Simon

Date: 22 Oct, 2009 15:28:20

Message: 26 of 29

Dear Isaac!

> no idea about all this memory go out? :(

No ideas. Please try to hide some parts of the code by commenting (perhaps simulating computations by RAND) and look if the memory problems disappear. Then the hidden parts could (!) contain the problem.

Some further ideas:
    presi=0;
    for j=1:numerocostituents
        if vettorepunteggio(1,j)>0
            presi=presi+1;
        end
    end
Faster:
  presi = sum(vettorepunteggio(1, 1:numerocostituents) > 0);
    
Similar to above:
        for j=1:numerocostituents
            if isnan(vettorepunteggio(1,j))==1
                vettorepunteggio(1,j)=-100;
            end
        end
Faster:
  vettorepunteggio(1, isnan(vettorepunteggio(1:numerocostituents))) = -100;
Or if [vettorepunteggio] has [numerocostituents] elements, this is even better:
  vettorepunteggio(isnan(vettorepunteggio)) = -100;

But I do not see a memory destructor. I ask again: No user defined MEX functions?!

Kind regards, Jan

Subject: Out of Memory

From: Isaac

Date: 23 Oct, 2009 11:32:19

Message: 27 of 29

"Jan Simon" <matlab.THIS_YEAR@nMINUSsimon.de> wrote in message <hbptmk$qtm$1@fred.mathworks.com>...
> Dear Isaac!
>
> > no idea about all this memory go out? :(
>
> No ideas. Please try to hide some parts of the code by commenting (perhaps simulating computations by RAND) and look if the memory problems disappear. Then the hidden parts could (!) contain the problem.
>
> Some further ideas:
> presi=0;
> for j=1:numerocostituents
> if vettorepunteggio(1,j)>0
> presi=presi+1;
> end
> end
> Faster:
> presi = sum(vettorepunteggio(1, 1:numerocostituents) > 0);
>
> Similar to above:
> for j=1:numerocostituents
> if isnan(vettorepunteggio(1,j))==1
> vettorepunteggio(1,j)=-100;
> end
> end
> Faster:
> vettorepunteggio(1, isnan(vettorepunteggio(1:numerocostituents))) = -100;
> Or if [vettorepunteggio] has [numerocostituents] elements, this is even better:
> vettorepunteggio(isnan(vettorepunteggio)) = -100;
>
> But I do not see a memory destructor. I ask again: No user defined MEX functions?!
>
> Kind regards, Jan

Thanks Jan for your suggestions :)
No i don't use any mex function!

Do You think it could help if i merge "regressione" e "regressionea" functions?

Subject: Out of Memory

From: Oleg Komarov

Date: 23 Oct, 2009 12:34:17

Message: 28 of 29

"Isaac " <asimov4000@hotmail.com> wrote in message <hbh9r3$7pi$1@fred.mathworks.com>...
> "Oleg Komarov" <oleg.komarov@hotmail.it> wrote in message <hbd2mr$t98$1@fred.mathworks.com>...
> > "Isaac " <asimov4000@hotmail.com> wrote in message <hbcao3$isg$1@fred.mathworks.com>...
> > > "Jan Simon" <matlab.THIS_YEAR@nMINUSsimon.de> wrote in message <hba66o$4k7$1@fred.mathworks.com>...
> > > > Dear Isaac!
> > > >
> > > > > anyway "REGRESS" is a matlab function which makes linear regression, you can see it here:
> > > > >
> > > > > http://www.mathworks.com/access/helpdesk/help/toolbox/stats/index.html?/access/helpdesk/help/toolbox/stats/regress.html&http://www.google.it/search?hl=it&source=hp&q=matlab+help+regress&btnG=Cerca+con+Google&meta=&aq=f&oq=
> > > > >
> > > > > i don't understand your question "what happens if it is called one time without and the next time with outputs?", can u explain me what you wanted to mean?
> > > >
> > > > In the source you've posted, REGRESS is called without output arguments and a few lines later with outputs. It was just a guess, that REGRESS was a user defined MEX function, which does not correctly handle calls with missing outputs and looses the memory there.
> > > > Nevertheless, calling REGRESS without outputs is not needed, is it?
> > > >
> > > > I'll take another look on your code, but it is a lot of characters...
> > > >
> > > > Kind regards, Jan
> > >
> > > You are right!!! it's a mistake :D i must delete that row (the one without output) !!! :)
> >
> > I noticed u use a function called "correlazionea". If u are calculating correlation coefficients with corrcoef, my personal suggestion is to loop the corrcoef through pairs of time series instead of calculating it at once...
> > Past experience taught me that is faster and avoids out of mem problems.
>
>
> thanks but i use only CORR :)

Thats waht corr about:
RHO = corr(X) returns a p-by-p matrix containing the pairwise linear correlation coefficient between each pair of columns in the n-by-p matrix X.
Same advice as before, this can run you into a memory problem.
Avoid to obtain a full correlation matrix.

Subject: Out of Memory

From: Isaac

Date: 23 Oct, 2009 13:32:21

Message: 29 of 29

"Oleg Komarov" <oleg.komarov@hotmail.it> wrote in message <hbs7s9$823$1@fred.mathworks.com>...
> "Isaac " <asimov4000@hotmail.com> wrote in message <hbh9r3$7pi$1@fred.mathworks.com>...
> > "Oleg Komarov" <oleg.komarov@hotmail.it> wrote in message <hbd2mr$t98$1@fred.mathworks.com>...
> > > "Isaac " <asimov4000@hotmail.com> wrote in message <hbcao3$isg$1@fred.mathworks.com>...
> > > > "Jan Simon" <matlab.THIS_YEAR@nMINUSsimon.de> wrote in message <hba66o$4k7$1@fred.mathworks.com>...
> > > > > Dear Isaac!
> > > > >
> > > > > > anyway "REGRESS" is a matlab function which makes linear regression, you can see it here:
> > > > > >
> > > > > > http://www.mathworks.com/access/helpdesk/help/toolbox/stats/index.html?/access/helpdesk/help/toolbox/stats/regress.html&http://www.google.it/search?hl=it&source=hp&q=matlab+help+regress&btnG=Cerca+con+Google&meta=&aq=f&oq=
> > > > > >
> > > > > > i don't understand your question "what happens if it is called one time without and the next time with outputs?", can u explain me what you wanted to mean?
> > > > >
> > > > > In the source you've posted, REGRESS is called without output arguments and a few lines later with outputs. It was just a guess, that REGRESS was a user defined MEX function, which does not correctly handle calls with missing outputs and looses the memory there.
> > > > > Nevertheless, calling REGRESS without outputs is not needed, is it?
> > > > >
> > > > > I'll take another look on your code, but it is a lot of characters...
> > > > >
> > > > > Kind regards, Jan
> > > >
> > > > You are right!!! it's a mistake :D i must delete that row (the one without output) !!! :)
> > >
> > > I noticed u use a function called "correlazionea". If u are calculating correlation coefficients with corrcoef, my personal suggestion is to loop the corrcoef through pairs of time series instead of calculating it at once...
> > > Past experience taught me that is faster and avoids out of mem problems.
> >
> >
> > thanks but i use only CORR :)
>
> Thats waht corr about:
> RHO = corr(X) returns a p-by-p matrix containing the pairwise linear correlation coefficient between each pair of columns in the n-by-p matrix X.
> Same advice as before, this can run you into a memory problem.
> Avoid to obtain a full correlation matrix.

But the datas are only 2-D so only 1 coefficient is calculated. i think this should not give any problems.

Tags for this Thread

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.

Contact us