How to do this more efficiently
古いコメントを表示
Hello,
I have this piece of code in MATLAB:
for kk=0:N-1
for mm=0:N-1
for pp=1:Np
for qq=1:Np
if ((kk*Ts+tau(pp)))<=(mm*Ts+tau(qq))) && ((kk+1)*Ts+tau(pp))>(mm*Ts+tau(qq)))
thetaSR=(((kk+1)*Ts+tau(pp)))-((mm*Ts+tau(qq))));
F_SR_MR(kk+1,mm+1)=F_SR_MR(kk+1,mm+1)+conj(H(pp))*H(qq)*(thetaSR*exp(1i*pi*fc**thetaSR)*sinc(fc*thetaSR));
end
which obviously is not very efficient. How can I re-write it more efficiently?
Thanks
6 件のコメント
the cyclist
2014 年 5 月 24 日
It's easier to help you if you include a self-contained piece of code (including values of N, tau, etc) so that we can run it without guessing what these values might be.
Jan
2014 年 5 月 24 日
The code does not run. Some end 's are missing an is not a valid Matlab operator.
S. David
2014 年 5 月 24 日
the cyclist
2014 年 5 月 25 日
Do you have a reference (e.g. an image you can post) that shows the mathematical formula you are trying to replicate? It might be easier to build the code directly from that rather than optimizing yours.
S. David
2014 年 5 月 25 日
採用された回答
その他の回答 (1 件)
the cyclist
2014 年 5 月 24 日
Especially if N is large, you might get a huge speedup if you preallocate the memory for F_SR_MR. Put the line
F_SR_MR = zeros(N,N);
ahead of the loops.
カテゴリ
ヘルプ センター および File Exchange で Type Checking についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!