how to reduce computation time for nested loops
古いコメントを表示
[N,M] = size(fft_img_test(:,:,1));
B = zeros(N,M,N,M);
for k=1:No_frames
for vy = 1:N
for vx = 1:M
for uy = 1:N
for ux = 1:M
u = uy+vy-2; v = ux+vx-2;
u = mod(u,N); v = mod(v,M);
u = u + 1; v = v + 1;
B(uy,ux,vy,vx) = B(uy,ux,vy,vx) + fft_img_test(uy,ux,k) * fft_img_test(vy,vx,k)...
* conj(fft_img_test(u,v,k));
end
end
end
end
end
phase_B = (angle(B/k));
5 件のコメント
Adam Danz
2020 年 1 月 2 日
It's easier if we can actually run the code but there are variable values missing that is preventing this. If you attach a mat file containing all needed variables to run the code, it would be helpful.
abdelelah alzahed
2020 年 1 月 2 日
Adam Danz
2020 年 1 月 2 日
You've got more than 536.8 million iterations (M * N * M * N * No_frames = 536870912).
Vectorization sometimes speeds up computation time but it's not always faster than loops and the expansion that may be required to do these computations using vectorization may exceed memory limits.
Could you explain in words the logic of this section below? It's not making much sense to me. When vx and vy equal 1, u and v are the same values as ux and uy. But then it starts to change when vx and vy are no longer 1.
u = uy+vy-2;
u = mod(u,N);
v = ux+vx-2;
v = mod(v,M);
u = u + 1;
v = v + 1;
conj(fft_img_test(u,v,k))
abdelelah alzahed
2020 年 1 月 2 日
編集済み: abdelelah alzahed
2020 年 1 月 2 日
Adam Danz
2020 年 1 月 2 日
"Therefore, once u or v are greater than N and M, respectively, the command lines, as stated above, will restart the calculation of the conjugate term to the starting point (1,1). "
Then shouldn't u and v always equal uy and ux (which isn't the case)?
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Loops and Conditional Statements についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!