[英]Creating 3D array (Matlab)
我目前正在建模冰蓋動力學。 我有一個循環計算表面能量平衡8760小時(1:tmax)和8個不同位置(1:no_stations)。 看起來如下:
tau=0.5;
albedo=0.35;
c0=-90;
c1=10;
for i=1:tmax
for e=1:no_stations
psi(i,e) = tau*(1-albedo)*insol(i,4)+c0+c1*temp_stations(i,e);
end
end
溫度數據(temp_stations)是一個8760x8陣列,相應的溫度為8個位置的8760小時,而insol(i,4)是8760x4的陣列,其中第四個colomn隨時間推移日照的演變。 我的問題:我想創建一個額外的維度,8760x8x61數組,其中c0不是常數,但在-140和-80之間變化:
c0=-140:1:-80;
我該怎么做呢? 我嘗試了一些東西,但似乎沒有成功。
謝謝!
對於需要擴展的情況,可以為矢量化解決方案帶來bsxfun
和permute
,就像這樣 -
parte2 = bsxfun(@plus,permute(c0,[1,3,2]),c1*temp_stations);
psi_out = bsxfun(@plus,tau*(1-albedo)*insol(:,4),parte2);
如果你不挖掘 bsxfun
或者你只想驗證矢量化方法的結果,這里是等效的循環代碼 -
for i=1:tmax
for e=1:no_stations
for k = 1:numel(c0)
psi(i,e,k) = tau*(1-albedo)*insol(i,4)+c0(k)+c1*temp_stations(i,e);
end
end
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.