Asked by Mohamed Elwakdy
on 6 Nov 2012

Dear Sir,

I have this error"Maximum variable size allowed by the program is exceeded" and i do know how i fixed it....

I obtained on this error when I wrote this code:

x1= double(imread('image1.jpg')); [C,S] = wavedec2(x1,1,'db5'); chd2 = wrcoef2('h',C,S,'db5',1); D1=[]; D1 =[D1 chd2]; [h w] = size(D1) s=2 t = 3; b = 2*t+1; N = h-b+1 M = w-b+1 L = N*M r = [1:s:N] r = [1:s:N] r = [r r(end)+1:N] c = [1:s:M] c = [c c(end)+1:M]

X = zeros(b*b,L,'single')% here, I obtained on the error massage?????

where i can not make zero matrix...

I would like to help me in fixed this error...if this possible??

Thank you very much

*No products are associated with this question.*

Answer by Walter Roberson
on 7 Nov 2012

You need to either reduce L somehow, or switch to a 64 bit MATLAB with more than 9 Gb of memory.

Consider whether you algorithm *really* needs all of those locations.

Consider whether you will have a lot of zeros; if so then sparse matrices might help.

What is it that you are trying to accomplish?

Walter Roberson
on 7 Nov 2012

*Why* do you want to make a testing block, etc. ? What are you trying to compute? For example is this a radar application?

Walter Roberson
on 7 Nov 2012

Answer by Jan Simon
on 6 Nov 2012

Edited by John Kelly
on 13 Nov 2013

The maximum size of variables can be optained by the command `computer`. Because your `b` is small, `L` must be giantic, such that the internal addressing gets an overflow. Depending on the architecture, this can be at 2^40 (divided by b*b=49...).

Jan Simon
on 7 Nov 2012

@Mohamed: As long as b=7, L = 23352784 should work. Are you sure that Matlab shows the error message for these values?

Exceeding the maximum size of arrays means, that you try to reserve more memory than Matlab and the operating system can access. But even below this limit you need very much RAM to process large arrays in a reasonable amount of time. So I assume, currently the problem you work on is too big for computers, and even if you split it in parts the calculations could take years.

But these assumptions are based on guessing only, because we still do not know the actual size of the problem, which produces the error message. Please type this in the command line:

dbstop if error

Then start your program. Matlab stops, when the error occurs and you can check the values of b and L.

Walter Roberson
on 7 Nov 2012

Opportunities for recent engineering grads.

## 5 Comments

## Sean de Wolski (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/52941#comment_109612

What is the value of

bandL?## Jan Simon (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/52941#comment_109637

b=7.This part of the code is not clear:

ris defined twice.r= 1:s:Nthe expressionr(end)+1equalsN+1. Therefore[r r(end)+1:N]is the same asr, becauseN+1:Nis the empty matrix.## Walter Roberson (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/52941#comment_109764

What is a typical value of L for your purpose?

## Randy Souza (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/52941#comment_114306

I have restored the original text of this question.

Mohamed Elwakdy, this question has a clear subject and multiple answers, so it may be valuable to someone else in the future. If you have a good reason why it should be removed from MATLAB Answers, please flag the question, explain why it should be deleted, and an administrator or high-reputation contributor will consider deleting the question. Please

do notsimply edit your question away.## Jan Simon (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/52941#comment_114316

@Randy: Thank you very much.