Vectorize product cell vectors
显示 更早的评论
I need to efficiently compute the quantity
where
and
,
, are
vectors and
are
sparse matrices.
If the matrices
were not sparse, then I could use a 3D array and probably vectorize some of the operations.
Right now, I am using a cell structure to store the matrices and I store the vectors in
matrices.
Here's the relevant part of the code that I am using:
res = 1;
for k = 1:N
res = res * (u(:, k).' * A{k} * v(:, k));
end
For reference, in my case
and
0, and the loop takes about 2 seconds. In my code, this loop is called several times, so it would make a great impact to reduce its runtime.
How can I improve the performance of the loop? Can it be vectorized? Should I be computing it in another way?
Thank you.
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!