out of memory, how to solve?

i was running a script and in the middle the program get me out of memory error. how can i solve it? the problem is probably the dimension of the workspace that is more than 2 GB at the time of the error.
thanks

6 Commenti

M
M il 5 Dic 2017
What is your script ?
matteo avanzi
matteo avanzi il 5 Dic 2017
Modificato: matteo avanzi il 5 Dic 2017
% load('untitled.mat')
j=ceil(t./86400); % is the day number
j1= 2*pi.*j/365.25; %day angle
% Position of the Sun
d = asin (0.3978*sin(j1 - 1.4 + 0.0355*sin(j1 - 0.0489))); % Sun declination rad
T = 0.261799*(time./3600 - 12); % convertire t ,T=hour angle
C11 = sin (j).*cos (d);
C13 = -cos (j).* sin (d);
C22 = cos (d);
C31 = cos (j).* cos (d);
C33 = sin (j).*sin (d);
h0=asin( C31.*cos(T)+ C33); % solar altitude h0
A0=acos((C11.*cos(T) + C13)./((C22.*sin(T)).^2+(C11.* cos (T) + C13).^2).^(1/2)); % solar azimuth A0
j11= asin(- cos (j).* sin( gN).* cos (AN)+ sin (j) .*cos (gN)); % j' o j11
l1 = atan(- (sin (gN).* sin (AN))./(sin (j) .*sin (gN) .*cos (AN)+ cos( j).* cos (gN)));
C_31 = cos (j11).* cos (d);
C_33 = sin (j11) .*sin (d);
dexp= asin(C_31.*cos(T - l1) + C_33); % the solar incidence angle
h_S=-C_33./C_31;
% Beam radiation
e = 1 + 0.03344.*cos(j1 - 0.048869);
G0 = I0.*e; % extraterrestrial irradiance
Dh0ref=0.061359.*(0.1594+1.123.*h0 + 0.065656.*(h0.^2))./(1 + 28.9344.*h0 + 277.3971.*(h0.^2));% atmospheric refraction component
h0ref = h0 + Dh0ref; % corrected solar altitude h0
a=exp(-z/8434.5); % p/p0
p=p0*exp(-z/8434.5);
m=a/(sin(h0ref)+0.50572.*(h0ref+6.07995).^-1.6364); %optical air mass
if m<=20 % Rayleigh optical thickness at air mass m
dR=1./(6.6296 + 1.7513.*m - 0.1202.*m.^2 + 0.0065.*m.^3 - 0.00013.*m.^4);
elseif m>20
dR= 1./(10.4 + 0.718.*m);
end
TLK=3;%air mass 2 Linke atmospheric turbidity factor tabella?
B0c = G0.*exp(-0.8662*TLK.*m.*dR);% beam irradiance normal to the solar beam
Bhc = B0c.*sin(h0);% beam irradiance on a horizontal surface
Bic = B0c.*sin(dexp);% beam irradiance on an inclined surface
% Diffuse radiation  
Tn= -0.015843 + 0.030543*TLK + 0.0003797*TLK^2; % transmission function
A11 = 0.26463 - 0.061581 *TLK + 0.0031408 *TLK^2;
if A11*Tn < 0.0022
A1 = 0.0022/Tn;
elseif A11*Tn >= 0.0022
A1 = A11;
end
A2 = 2.04020 + 0.018945 *TLK - 0.011161 *TLK^2;
A3 = -1.3025 + 0.039231 *TLK + 0.0085079* TLK^2;
Fd= A1 + A2*sin(h0) + A3* (sin (h0).^2); % solar altitude function
Dhc = G0.*Tn.*Fd; % diffuse component on a horizontal surface
A_LN = A0 - AN;
if -p <= A_LN <= p
ALN = A_LN;
elseif A_LN > p
ALN = A_LN - 2*p;
elseif A*LN < -p
ALN = A*LN + 2*p;
end
G0h = G0.*sin (h0);
Kb = Bhc./G0h; % measure of the amount of beam irradiance available
N = 0.00263 -0.712.*Kb - 0.6883.*Kb.^2;
ri= (1 + cos (gN))/2; % fraction of the sky dome viewed by an inclined surface
F=ri+(sin (gN) - gN *cos(gN) - p*(sin(gN/2))^2).*N; % function accounting for the diffuse sky irradiance
if h0>= 0.1 % radianti
Dic = Dhc.*(F.*(1 - Kb) + Kb.*sin(dexp)/sin (h0));
elseif h0 < 0.1
Dic = Dhc (F.*(1 - Kb) + Kb.*sin(gN).*cos(ALN)/(0.1 - 0.008.*(h0)));
end
% Ground reflected radiation 
Ghc = Bhc + Dhc; % global horizontal irradiance Ghc
rg = (1 - cos (gN))/2;
Ri = rg1 *Ghc* rg; % rg1 è sigma
if (T<h_S && T>-h_S) % if true is day
G=Bic+Dic+Ri; % [w/m^2] radiazione globale su una superficie comunque orientata
else
G=0;
end
end
matteo avanzi
matteo avanzi il 5 Dic 2017
Modificato: matteo avanzi il 5 Dic 2017
i get the error at
B0c = G0.*exp(-0.8662*TLK.*m.*dR);% beam irradiance normal to the solar beam
Bhc = B0c.*sin(h0);% beam irradiance on a horizontal surface
Bic = B0c.*sin(dexp);% beam irradiance on an inclined surface
the untitled.mat is 325 MB
Are you using R2016b or later? If you are, then check to see if you are accidentally using a mix of row vectors and column vectors: R2016b and later treats that as if you had used bsxfun() instead of giving an error.
R2017b, i have 30 31536000x1 double arrays, 2 1x31536000 an 15 scalar.
the problem are the 2 1x31536000?
ok thanks that's was the problem

Accedi per commentare.

Risposte (1)

Rik
Rik il 5 Dic 2017
As Walter hinted, the problem is implicit expansion:
A=1:4;
B=A';
A.*B
ans =
1 2 3 4
2 4 6 8
3 6 9 12
4 8 12 16
So your syntax expands the already large vectors to an even larger matrix. Adding a transpose to one of the vectors will solve this.

Categorie

Scopri di più su Gravitation, Cosmology & Astrophysics in Centro assistenza e File Exchange

Richiesto:

il 5 Dic 2017

Commentato:

il 5 Dic 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by