Multiply elements of a matrix along its third dimension
For programming in MATLAB, how can I write a function that will take a stack of matrices in a variable (let's say M
) and multiply them together and return in answer in an output argument.
It would be preferred to put M
as an input argument of the function. And it might be easier to use for loops to multiply each layer to the previous.
Help would be greatly appreciated, thank you!
开发者_高级运维To help start:
M(:,:,1)=[1 2,3 4]; %first layer
M(:,:,2)=[5 6,7 8]; %second layer
That function is called prod
. Try this
newM = prod(M,3);
精彩评论