Mutiply 4d array of size (360,210,63,48) by vector of length 48?

I have a 4d array Final of size (360,210,63,48) that I want to multiply by the vector [0:1/12:3.99] which is length 48. For example, I want Final2=(Final(:,:,:,1).*0, Final(:,:,:,2).*0.0833) etc. I have tried Final2=Final.*[0:1/12:3.99] but I get the error ??? Error using ==> times Number of array dimensions must match for binary array op.
Any suggestions? I know I can do this in a loop, but I would much prefer not to.

 Accepted Answer

I think this will do it if you want Final2 to be the same shape as Final (not at a machine with MATLAB right now):
z = size(Final);
FinalR = reshape(Final,[],48);
Final2 = bsxfun(@times,FinalR,v); % Assumes v is a row vector
Final2 = reshape(Final2,z);
EDIT
Or simply:
Final2 = bsxfun(@times,Final,reshape(v,1,1,1,48));

More Answers (0)

Categories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!