开发者

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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜