对数组进行预分配后,反而严重降低了赋值的速度,请问如何解决?
이전 댓글 표시
数组预分配后,赋值操作反而需要更多的时间,矩阵的维度越大,预分配后进行赋值需要的时间更多。
注释掉预分配语句后,赋值时间减少
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!


