单元阵列中的矩阵相乘 [英] Multiplying matrices in a cell array

查看:90
本文介绍了单元阵列中的矩阵相乘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设您有一个N x 1的单元阵列,其中每个组成单元都是一个m x m的矩阵.我想要这些矩阵的矩阵乘积(即不是逐项乘法),所以如果E_i是单元格数组中的第i个矩阵.我想计算E_1 * E_2 * ... * E_N.有矢量化方法的想法吗?

Suppose you have an N x 1 cell array where each constituent cell is an m x m matrix. I would like the matrix product (i.e. not entry-by-entry multiplication) of these matrices, so if E_i is the ith matrix in the cell array. I would like to compute E_1 * E_2 * ... * E_N. Any ideas for a vectorized approach to this?

推荐答案

最直接的方法是执行此操作(其中p是您的答案,cellarray是您的单元格数组). *是矩阵乘法,而.*是您希望避免的逐元素乘法.

The most direct way is to do this (where p is your answer and cellarray is your cell array). * is the matrix multiplication while .* is the element-by-element multiplication you wish to avoid.

p = 1;    
for i = 1:N,
   p = p*cellarray{i};
end

这篇关于单元阵列中的矩阵相乘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆