【问题标题】:Matlab : 3d matrix divided by 2d matrixMatlab:3d矩阵除以2d矩阵
【发布时间】:2013-09-21 03:04:29
【问题描述】:

我在 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) ;

【问题讨论】:

    标签: matlab netcdf


    【解决方案1】:

    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);
    

    【讨论】:

      猜你喜欢
      • 2015-02-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多