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일
What do you mean "doesn't seem to work?" Please be specific, and if you can provide an example, it would really help.
ak135AK
ak135AK 2015년 7월 30일
편집: ak135AK 2015년 7월 30일
this code works, but my implementations of vectorization do not... I am not sure, if it is even possible, is it?
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.
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일

0 개 추천

Just preallocating P will speed this up a lot
P = cell(Nx^2,1)
before the loop

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2015년 7월 30일

편집:

Jon
2015년 7월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by