How to loop half matrix

조회 수: 6(최근 30일)
Mohammad Ezzad Hamdan
Mohammad Ezzad Hamdan 2021년 5월 15일
댓글: Mohammad Ezzad Hamdan 2021년 5월 16일
for i=2:nhx-1
for j=2:nhy-1
Unew(i,j) = U(i,j)-dt*(P(i+1,j)-P(i-1,j))/(2*hx)...
+nu*dt*(1/(hx*hx)*(U(i+1,j)-2.*U(i,j)+U(i-1,j))...
+1/(hy*hy)*(U(i,j+1)-2.*U(i,j)+U(i,j-1)))...
-dt*U(i,j)/(hx)*(U(i,j)-U(i-1,j))...
-dt*V(i,j)/(2*hy)*(U(i,j+1)-U(i,j-1));
end
end
Hi, the Unew produce something like this "1 2 3 4 5 4 3 2 1" as an example. I would like to calculate just half of the j domain so that Unew will produce "1 2 3 4 5" and the following ''4 3 2 1" will just be reflected from "1 2 3 4" in order to shorten the running time.

채택된 답변

Jan
Jan 2021년 5월 15일
for i = 2:nhx-1
for j = 2:(nhy + 1) / 2
Unew(i, j) = ...
Unew(i, nhy - j + 1) = Unew(i, j);
end
end
  댓글 수: 1
Mohammad Ezzad Hamdan
Mohammad Ezzad Hamdan 2021년 5월 16일
Thanks Jan!!!

댓글을 달려면 로그인하십시오.

추가 답변(0개)

태그

Community Treasure Hunt

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

Start Hunting!

Translated by