对数组进行预分配后,反而严重降低了赋值的速度,请问如何解决?
Show older comments
数组预分配后,赋值操作反而需要更多的时间,矩阵的维度越大,预分配后进行赋值需要的时间更多。
注释掉预分配语句后,赋值时间减少
clearvars
test_h_matx_diag = zeros(1024,1024,360); % 预分配语句
h_matx = rand(1024,1,360);
h_matx = exp(-1j*2*pi*h_matx);
for ii = 1:size(h_matx,3)
temp1 = diag(h_matx(:,:,ii));
test_h_matx_diag(:,:,ii) = temp1; % 赋值的速度受预分配的影响
end
Accepted Answer
More Answers (0)
Categories
Find more on 性能和内存 in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


