对数组进行预分配后,反而严重降低了赋值的速度,请问如何解决?
Mostrar comentarios más antiguos
数组预分配后,赋值操作反而需要更多的时间,矩阵的维度越大,预分配后进行赋值需要的时间更多。
注释掉预分配语句后,赋值时间减少
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
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre 性能和内存 en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


