フィルターのクリア

How to speed up this loops?

1 回表示 (過去 30 日間)
Alex Kurek
Alex Kurek 2016 年 6 月 1 日
回答済み: Ahmed Rashid 2016 年 6 月 2 日
Hi,
Is there a way to speed up this?
maxN = 120;
x = -30:0.1:30;
xElements = numel(x);
u_mn = zeros(xElements, xElements);
for m = -maxN:2:maxN
for i = 1 : xElements
for j = 1 : xElements
u_mn(i, j) = sqrt((n+1)/pi) * besselj(m+1, 2*sqrt(x(i)^2 + x(j)^2)) / sqrt(x(i)^2 + x(j)^2)^(m+1) * (x(i) + 1i*x(j))^m;
end
end
end
Best regards, Alex
  4 件のコメント
Walter Roberson
Walter Roberson 2016 年 6 月 1 日
You do not store the results for each different m, and you are not summing them or anything like that, so the effect is as if you had only done the final m value.
Alex Kurek
Alex Kurek 2016 年 6 月 2 日
Thanky you, obviously, you are right. the middle line in the loops should look like this:
for m = -maxN:2:maxN
for i = 1 : xElements
for j = 1 : xElements
u_mn(i, j) = u_mn(i, j) + sqrt((n+1)/pi) * besselj(m+1, 2*sqrt(x(i)^2 + x(j)^2)) / sqrt(x(i)^2 + x(j)^2)^(m+1) * (x(i) + 1i*x(j))^m;
end
end
end
But still, how to speed this up? Its not working to fast right now.

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

採用された回答

Ahmed Rashid
Ahmed Rashid 2016 年 6 月 2 日
You can create a mex function of your firstTestFunct by
xx = 1;
codegen firstTestFunct -args {xx, xx, xx, xx}
You need to do it only once. It will generate a mex file. To call the generated mex file, you just need to replace firstTestFunct with firstTestFunct_mex .

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB Algorithm Acceleration についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by