簡體   English   中英

Matlab:3d矩陣除以2d矩陣

[英]Matlab : 3d matrix divided by 2d matrix

我在MATLAB中有一個4d矩陣(按逐個緯度逐個經度)需要除以一個3d矩陣中的所有組的總和值(逐個緯度的經度)。一段的時間。 我想有一個4d矩陣,在4d矩陣中呈現每組的分數閥(逐個緯度地逐個緯度)我該怎么做?

例如(netcdf文件):

short npp(time, pft, latitude, longitude) ;
short npptot(time, latitude, longitude) ;

我喜歡這樣計算:

fraction = npp ./ npptot

結果應該是4d矩陣,逐個緯度地逐個緯度。

short fraction(time, pft, latitude, longitude) ;

bsxfun僅用於此類維度擴展。 訣竅是尺寸需要精確匹配,除了要擴展的尺寸。 這意味着你的3d矩陣需要是一個4d時間x 1 x lat x lon矩陣:

npptot_reshaped = reshape(npptot, [size(npptot,1) 1 size(npptot,2) size(npptot,3)]);
fraction = bsxfun(@rdivide, npp, npptot_reshaped);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM