P. 1
MATLAB Array Manipulation Tips and Tricks

MATLAB Array Manipulation Tips and Tricks

4.7

|Views: 10,836|Likes:
Published by eebeta
from Internet
from Internet

More info:

Published by: eebeta on Feb 14, 2009
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF or read online from Scribd
See more
See less

07/02/2013

Assume X is an m-by-n-by-p-by-q-by-... array and Y is a k-by-m matrix and you want to construct
a new k-by-n-by-p-by-q-by-... array Z, where

Z(:,:,i,j,...) = Y * X(:,:,i,j,...);

for alli=1,...,p, j=1,...,q, etc. This can be done with nested for-loops, or by the following
vectorized code

sx = size(X);
sy = size(Y);
Z = reshape(Y * X(:,:), [sy(1) sx(2:end)]);

The above works by reshaping X so that all 2D slices X(:,:,i,j,...) are placed next to each
other (horizontal concatenation), then multiply with Y, and then reshaping back again.
The X(:,:) is simply a short-hand for reshape(X, [sx(1) prod(sx)/sx(1)]).

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->