Multiplies the 2D slices in a 3D matrix by individual scalars. function A = multiscale(scale, A) Given a vector scale of length N and a 3-D array A of size n-by-m-by-N, returns an array B of same size as A such that B(:, :, k) = scale(k) * A(:, :, k); See also: multiprod multitransp multitrace cmultiscale
0001 function A = multiscale(scale, A) 0002 % Multiplies the 2D slices in a 3D matrix by individual scalars. 0003 % 0004 % function A = multiscale(scale, A) 0005 % 0006 % Given a vector scale of length N and a 3-D array A of size 0007 % n-by-m-by-N, returns an array B of same size as A such that 0008 % B(:, :, k) = scale(k) * A(:, :, k); 0009 % 0010 % See also: multiprod multitransp multitrace cmultiscale 0011 0012 % This file is part of Manopt: www.manopt.org. 0013 % Original author: Nicolas Boumal, Dec. 30, 2012. 0014 % Contributors: 0015 % Change log: 0016 % Aug. 29, 2021 (NB): 0017 % Corrected bug that occurred for complex 'scale' vector. 0018 % Sep. 5, 2021 (NB): 0019 % Using .* rather than bxsfun as a preferred way: this is faster. 0020 % Kept the bsxfun code in a try/catch in case this causes trouble 0021 % with older versions of Matlab (unsure whether it would). 0022 0023 assert(ndims(A) <= 3, ... 0024 ['multiscale is only defined for arrays of 3 or fewer ' ... 0025 'dimensions.']); 0026 0027 [n, m, N] = size(A); 0028 0029 assert(numel(scale) == N, ... 0030 ['scale must be a vector whose length equals the third ' ... 0031 'dimension of A, that is, the number of 2D matrix slices ' ... 0032 'in the 3D array A.']); 0033 0034 try 0035 A = A .* reshape(scale, [1, 1, N]); 0036 catch 0037 scale = scale(:); 0038 A = reshape(bsxfun(@times, reshape(A, n*m, N), scale.'), n, m, N); 0039 end 0040 0041 end