我正在尝试通过将一些迭代转换为Matlab中的矩阵运算来提高代码的性能.其中之一是以下代码,我需要弄清楚如何避免在操作中使用循环.
I am trying to improve the performance of my code by converting some iterations into matrix operations in Matlab. One of these is the following code and I need to figure out how can I avoid using loop in the operation.
此处gamma_ic&弓是二维矩阵. c& z是从外部迭代中设置的变量.
Here gamma_ic & bow are two dimensional matrices. c & z are variables set from outer iterations.
for z=1:maxNumber, for c=1:K, n = 0; for y2=1:number_documents, n = n+(gamma_ic(y2,c)*bow(y2,z)); end mu(z,c) = n / 2.3; end end感谢您的帮助.
编辑.添加了c和z的循环.迭代一直进行到gamma_ic& amp;中的最大索引为止.弓.添加了mu,这是另一个二维矩阵,用于显示n的用法.
Edit. Added The loop for c and z. The iteration goes on till the maximum indices in gamma_ic & bow. Added mu which is another two dimensional matrix to show usage of n.
推荐答案这应该对您有用,以获得mu,这似乎是所需的输出-
This should work for you to get mu, which seems to be the desired output -
mu = bow(1:number_documents,1:maxNumber).'*gamma_ic(1:number_documents,1:K)./2.3更多推荐
向量化算术运算
发布评论