Effacer les filtres
Effacer les filtres

Replace nested loops with a matrix

1 vue (au cours des 30 derniers jours)
Mohammad Ezzad Hamdan
Mohammad Ezzad Hamdan le 9 Mai 2021
I have to optimize this code but i am not sure how to turn it into a matrix.
for i=2:nhx-1
for j=2:nhy-1
U(i,j)= U(i,j)-dt*(Pc(i+1,j)-Pc(i-1,j))/(2*hx);
end
end

Réponse acceptée

Bruno Luong
Bruno Luong le 9 Mai 2021
i=2:nhx-1;
j=2:nhy-1;
U(i,j)= U(i,j)-dt*(Pc(i+1,j)-Pc(i-1,j))/(2*hx);

Plus de réponses (1)

Dyuman Joshi
Dyuman Joshi le 9 Mai 2021
Unew = zeros(nhx, nhy);
Unew(2:nhx-1, 2:nhy-1)=U(2:nhx-1, 2:nhy-1)-dt.*(P(3:nhx,2:nhy-1)-P(1:nhx-2,2:nhy-1))./(2*hx);

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by