OUT OF MEMORY IN MATLAB
2 views (last 30 days)
Show older comments
hi all dear i want to run my program that it has very large matrix and when it runs .i see out of memory error.how can i fix that?
if true
clc;
close all;
clear all;
t=0:0.0001:900;
number=200;
%==========================================================================
synchronization_time=400;
dysynchronization_time=550;
c0_value=1.5;
k=0;
delay=2.5;
a=1;
%-------------------------------------------------------------------------
zbar=zeros(number,length(t));
xbar=zeros(number,length(t));
ybar=zeros(number,length(t));
x=zeros(number,length(t));
y=zeros(number,length(t));
z=zeros(number,length(t));
xs=zeros(1,length(t));
ys=zeros(1,length(t));
s=zeros(1,length(t));
andaze_s=zeros(1,length(t));
delta=zeros(1,number);
zbars=zeros(1,length(t));
zbars_conj=zeros(1,length(t));
zbars_tavan2=zeros(1,length(t));
sum1=zeros(number,length(t));
sum3=zeros(number,length(t));
sum4=zeros(number,length(t));
desync=0;
delta=zeros(1,number);
init=2*rand(1,2*number)-1;
f=.05;
%======================================================
c0=0;
for l=1:number
z(l,1)=init(1,l)+j*init(1,2*l);
end
xs(1)=1;
ys(1)=1;
omega=normrnd(((2*pi)/5),0.1,number,1);
%===================================================
for l=1:length(t)-1
if (l>(synchronization_time*10000)&&l<((synchronization_time+20)*10000))
c0=c0_value;
end
if l>(dysynchronization_time*10000)
k=100;
end
%===================================================
sum2=0;
if l>(26000)
for d=1:number
sum2=(x(d,l)+j*y(d,l))+sum2;
end
zbars(l)=sum2/number;
zbars_conj(l)=conj(zbars(l-(delay*10000)));
zbars_tavan2(l)=(zbars(l)^2);
s(l)=k*zbars_tavan2(l)*zbars_conj(l);
xs(l)=real(s(l));
ys(l)=imag(s(l));
andaze_s(l)=abs(s(l));
end
for m=1:number
delta(m)=1/(1+(f^2)*((abs((number/2)-m))^2));
z(m,l+1)=z(m,l)+.0001*((a+j*omega(m)-(abs((z(m,l)))^2))*(z(m,l))+c0*zbar(m,l)+(delta(m)*(s(l))));
x(m,l+1)=real(z(m,l+1));
y(m,l+1)=imag(z(m,l+1));
end
for h=1:number
for g=1:number
sum1(h,l)=(1/(1+f*abs(h-g)))*((z(g,l)))+sum1(h,l);
end
zbar(h,l+1)=sum1(h,l)/number;
end
if l==5525
hg=0
end
%==========================================================================
end
figure
color_fig=rand(1,120);
for f=1:30
plot(x(f,:),'color',[color_fig(f) color_fig(2*f) color_fig(3*f)]);
hold on;
end
figure
plot(andaze_s);
figure
plot(real(s));
figure
plot(imag(s));
end
1 Comment
Answers (3)
Andreas Goser
on 29 Jan 2013
I was tempted to suggest more RAM, but seriously in most applications I see, users simply do not plan / think of "How much data do I need to answer my question?"
There are different application with different patterns.
1. Measured data to be read and postprocessed. Do I really need 1 ms sampled data to be able to identify frequencies of 50 Hz?
2. Simulations: Do I really need all the results of all channels of the simulation? Or isn't it enough to see the last 10 seconds of this one signal?
...
You get the picture...
0 Comments
Image Analyst
on 29 Jan 2013
Heeding Andreas's advice, why don't you try your code with this:
t=0:1:900; % Perhaps this resolution is good enough.
instead of
t=0:0.0001:900; % Way more resolution than is needed.
0 Comments
Jan
on 29 Jan 2013
Edited: Jan
on 29 Jan 2013
Each of the 9 matrices need 14'400'000'000 Bytes. So about 14*9=126 Gigabyte free memory are the absolute minimum, 172GB would be more reliable.
The usual suggestion is:
- Install more RAM
- Care for a proper pre-allocation
- Install more RAM
- Run a 64-bit version of Matlab
- Install more RAM
- Close other processes
- Install more RAM
- Use the smallest data type, which represents your data exactly, e.g. a single occupies 4 bytes instead of 8 for a double.
- Install more RAM
2 Comments
Walter Roberson
on 29 Jan 2013
Jan forgot to mention that you should consider installing more RAM!
On the other hand, if you need 128 gigabyte, you probably need to re-examine your algorithm.
Jan
on 29 Jan 2013
Oh, sorry, you are right, Walter, I forgot this important detail. And besides the constructive advice to increase the RAM, reducing the resolution of the examination is an obvious strategy also, therefore I've voted for Andreas' and IA's suggestions.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!