对数组进行预分配后,反而严重降低了赋值的速度,请问如何解决?
古いコメントを表示
数组预分配后,赋值操作反而需要更多的时间,矩阵的维度越大,预分配后进行赋值需要的时间更多。
注释掉预分配语句后,赋值时间减少
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
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で 性能和内存 についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


