Vectorization of double for loop
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
ak135AK
am 30 Jul. 2015
Bearbeitet: Jon
am 30 Jul. 2015
I am vectorizing following code,doesnt seem to work. I will appreciate any help !
aux=1;
n = sqrt(max(size(u)));
cut = n / Nx;
u = reshape(u, n, n);
for i = 0 : Nx-1
for j = 0 : Nx-1
P{aux}{1} = u(1+ i*cut: (i+1)*cut,1+ j*cut: (j+1)*cut);
aux = aux +1;
end
end
4 Kommentare
Akzeptierte Antwort
Sean de Wolski
am 30 Jul. 2015
Just preallocating P will speed this up a lot
P = cell(Nx^2,1)
before the loop
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!