Vectorization of double for loop
조회 수: 1 (최근 30일)
이전 댓글 표시
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
채택된 답변
Sean de Wolski
2015년 7월 30일
Just preallocating P will speed this up a lot
P = cell(Nx^2,1)
before the loop
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!