# How to make 2 for loops code to run faster?

1 ビュー (過去 30 日間)
Amjad Iqbal 2022 年 9 月 13 日
コメント済み: Bruno Luong 2022 年 9 月 14 日
Dear MATLAB Experts;
I want to make this part of code to run faster it takes hours to process. there are two for loops which take a lot of time to compile the code.
I need your guidance to make this code run faster.
Thank you so much.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
x_vect = (-5:0.02:5);
y_vect = (-5:0.02:5);
z_vect = 0;
[x_mat,y_mat,z_mat] = meshgrid(x_vect,y_vect,z_vect);
img = zeros(size(x_mat));
tic;
for ii = 1:2:length(angle)
dR = sqrt((R0*cos(alpha*pi/180).*cos(angle(ii)*pi/180) + x_mat).^2 ...
+ (R0*cos(alpha*pi/180).*sin(angle(ii)*pi/180) + y_mat).^2 +...
(z_mat - R0*sin(alpha*pi/180)).^2) - R0;
for jj = 1:length(Fvec)
img = img + data(ii,jj).*exp(1j*4*pi*Fvec(jj)/c0*dR);
end
end
toc;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
##### 12 件のコメント表示 11 件の古いコメント非表示 11 件の古いコメント
Bruno Luong 2022 年 9 月 14 日
It is NOT 2D filter or convolution. Your "kernel" change form. It is NOT Fourier transform either. Tere is perhaps no fancy algorithms that can possiblyy reduces the flops of your calculation.

サインインしてコメントする。

### カテゴリ

Find more on Loops and Conditional Statements in Help Center and File Exchange

R2021a

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by