我必须在不支持bsxfun
的旧版本上运行Matlab代码,并且需要编写
matx = bsxfun(@rdivide, matx, reshape(f, 1, 1, length(f)));
我试过这个
matx=matx./ones(size(reshape(f, 1, 1, length(f)),1));
但结果错了
matx
大小为246x301x81
在调用使用bsxfun
f
大小为1x81
答案 0 :(得分:1)
由于matx
是一个3D数组,而f
是一个长度等于dim-3
matx
中元素数量的行向量,您可以执行{{使用repmat
等效扩展/复制,然后像这样执行元素划分 -
% Get size of matx
[m1,n1,r1] = size(matx);
%// Replicate f to the size of matx and perform elementwise division
matx = matx./repmat(permute(f,[1 3 2]),[m1 n1 1])