nested loops of different dimension without using "for loops"

13 ビュー (過去 30 日間)
thebasher
thebasher 2014 年 2 月 1 日
コメント済み: Andrei Bobrov 2014 年 2 月 2 日
Hi, I'm having a problem implementing my code:
reflectance=0.2;
tilt=18;
Lat=37.4;
phi_c=0;
n=1:365; %Days in a year
delta=23.45*sind(360*(n-81)/365);
h=11:-1:-12; %hours
beta=asind(cosd(Lat).*cosd(delta).*cosd(15.*h)+sind(Lat).*sind(delta))
phi_s=asind((cosd(delta).*sind(15.*h))./cosd(beta))
theta=acosd(cosd(beta).*cosd(phi_s-phi_c).*sind(tilt)+sind(beta).*cosd(tilt))
theta=theta'
I_bc=DNI*cosd(theta)
I_rc=GHI.*reflectance.*((1-cosd(tilt))./2)
I_dc=DHI.*((1+cosd(tilt))./2)
I_c=I_bc+I_dc+I_rc
Basically, I want to compute the calculations for each hour (24 in total) for each day n (365 days). DNI, GHI and DHI are 8760x1 values each (24*365=8760).
I was told earlier to implement the bsxfun function, which is useful for different dimensions. Here is my attempt, but it's still not right:
n=1:365;
delta=23.45*sind(360*(n-81)/365);
h=11:-1:-12;
beta=asind(cosd(Lat).*bsxfun(@plus,bsxfun(@times,cosd(delta),cosd(15.*h)'),(sind(Lat).*sind(delta))))
theta=acosd(cosd(beta).*cosd((asind((cosd(delta).*sind(15.*h))./cosd(beta)))-phi_c).*sind(tilt)+bsxfun(@times,sind(beta),cosd(tilt)))
theta=theta'
I_bc=bsxfun(@times,DNI,cosd(theta))
I_rc=GHI.*reflectance.*((1-cosd(tilt))./2)
I_dc=DHI.*((1+cosd(tilt))./2)
I_c=I_bc+I_dc+I_rc
Is there any chance someone can help me on this?

採用された回答

Andrei Bobrov
Andrei Bobrov 2014 年 2 月 1 日
編集済み: Andrei Bobrov 2014 年 2 月 2 日
ct = cosd(tilt);
p1 = cosd(15.*h(:))*cosd(delta);
sb = bsxfun(@plus,cosd(Lat)*p1,sind(Lat)*sind(delta));
cb = cosd(asind(sb));
phi_s = asind(bsxfun(@rdivide,p1,cb));
costheta = cb.*cosd(phi_s-phi_c).*sind(tilt)+sb.*ct;
s = size(sb);
I_bc = reshape(DNI,s).*costheta;
I_rc = reshape(GHI,s)*reflectance*(1-ct)/2;
I_dc = reshape(DHI,s)*(1+ct)./2;
I_c = I_bc+I_dc+I_rc;
ADD
I_c_out = I_c(:);
  2 件のコメント
thebasher
thebasher 2014 年 2 月 2 日
Thanks for your reply. I appreciate you taking the time to help me. This results in many lines on my graph. Is it possible to plot one line that represents the whole year?
Andrei Bobrov
Andrei Bobrov 2014 年 2 月 2 日
see code after ADD string

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by