Slowing down when doing calculations with catenated matrix
2 次查看(过去 30 天)
显示 更早的评论
I'm trying to speed up my code. The original code is here:
I think the "kron" function is repeatedly calculated within the loop "i=1:3", so I moved the kron function outside it:
And it turned out to be slower, even when the use of "kron" is reduced by three times. The reason I found out later is catenating the three copies of "temp" into the third dimension, and I tried the following code:
And this time it's much faster. So my question is why working with catenated matrix is very slow, when the calculation is the same. What in general is to be avoided? Thanks!
0 个评论
采纳的回答
Rashed Mohammed
2021-3-18
Hi Weixin,
Please go through https://www.mathworks.com/help/matlab/matlab_prog/techniques-for-improving-performance.html for improving performance of your code. It outlines the best practices while writing MATLAB code aimed at performance.
Hope this helps.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!