nested for loop assigning to a matrix
Show older comments
Hi I'm having trouble having all the outputs of this for loop assigned to a matrix, it is only assigning the last run. I'm trying to find the solar absorption when the cloud cover(nc) is 0, at the latitude(lat) 0.
day=365; hr=24; abs_sun_rad= nan(day,hr);
for days = 1:day;
for hrs=0:hr;
sec= hrs*3600;
del = -23.45*(pi/180)*(cos((2*pi/365)*(days+9)));
S=1357+45*(cos(((2*pi)/86400)*days));
sin_h =(sind(lat)*sind(del)+ cosd(lat)*cosd(del)*cosd((2*pi/86400)*(sec+43200)));
h=asin(sin_h);
m=(1/sin_h);
Cext=0.128-0.0235*(log(m));
i=((pi/2)-h);
j=asin(0.75*(sin(i)));
r=(0.5)*(abs((sin(i-j).^2)/(sin(i+j).^2)+(tan(i-j).^2/tan(i+j).^2)));
if h>0 ;
Insd=S*(exp(-Cext(:,1)*m))*(sin_h*(1-0.71*nc));
end
if h<=0;
Insd=0;
end
Insg = 0.52*nc*Insd(:,1);
abs_sun_rad(day,hr)=Insd*(1-r)+0.97*(Insg);
end
end
any help is great appreciated thanks
Answers (1)
Chad Greene
on 12 Nov 2014
Edited: Chad Greene
on 12 Nov 2014
0 votes
It looks like you're assigning abs_sun_rad(day,hr)=Insd..., but day and hr are scalar values that do not change. Perhaps you mean abs_sun_rad(days,hrs+1)=Insd...
Categories
Find more on Solar Power in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!