How to speed up this loops?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Alex Kurek
am 1 Jun. 2016
Beantwortet: Ahmed Rashid
am 2 Jun. 2016
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 Kommentare
Walter Roberson
am 1 Jun. 2016
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.
Akzeptierte Antwort
Ahmed Rashid
am 2 Jun. 2016
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu MATLAB Algorithm Acceleration finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!