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 个评论
Jon
Jon 2015-7-30
编辑:Jon 2015-7-30
It doesn't seem possible to me, but one of the more experienced users here might be able to make it happen.
ak135AK
ak135AK 2015-7-30
u is vector 1 x n2, then is gets reshaped and is cut into 4 partitions in middle, something like:
% omega 1 | omega 2
% ------------------
% omega 3 | omega 4
and each part is saved into P

请先登录,再进行评论。

采纳的回答

Sean de Wolski
Sean de Wolski 2015-7-30
Just preallocating P will speed this up a lot
P = cell(Nx^2,1)
before the loop

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by