1

我在 MATLAB 中有一个 4d 矩阵(time-by-group-by-latitude-by-longitude)需要除以 3d 矩阵(time-by-latitude-by-longitude)中所有组的总和值一段的时间。我想要一个 4d 矩阵,在 4d 矩阵中显示每组的分数阀(时间-by-group-by-latitude-by-longitude)我该怎么做?

例如(netcdf 文件):

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

我喜欢做这个计算:

fraction = npp ./ npptot

结果应该在一个 4d 矩阵中,按时间按组按纬度按经度。

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

1 回答 1

4

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);
于 2013-09-16T20:53:29.153 回答