Repeat Lines 14 to 25 a specified number of times, only print final matrix
Afficher commentaires plus anciens
I'm really new to matlab. How would I go about getting this to repeat from line 14 to 25 a certain number of times (iterate) for instance 131 times. I don't want it to print the result at each iteration just the resulting matrix after 131 iterations.
clear;
HOLD=zeros(23,23);
HNEW=zeros(23,23);
R=zeros(23,23);
%Initial Value of matrix
for i=1:23
for j=1:23
HOLD(i,j)=10
HNEW(i,j)=10
end
end
R(22,2)=-0.2;
%implement implicit method
for i=2:22
for j=2:22
H1=0.25*(HOLD(i,j+1)+HOLD(i,j-1)+HOLD(i-1,j)+HOLD(i-1,j-1))
H2=0.25*(HNEW(i,j+1)+HNEW(i,j-1)+HNEW(i-1,j)+HNEW(i-1,j-1))
HNEW(i,j)=(1/((100*100*0.002/4/300/0.1)+1))*(H2+100*100*0.002/4/300/0.1*HOLD(i,j)+100*100*R(i,j)/4/300)
end
end
for i=2:22
for j=2:22
HOLD(i,j)=HNEW(i,j)
end
end
%No Flow Boundarys
for j=1:23
HOLD(1,:)=HOLD(3,:)
HOLD(23,:)=HOLD(21,:)
end
for i=1:23
HOLD(:,1)=HOLD(:,3)
HOLD(:,23)=HOLD(:,21)
end
%Need to repeat from line 14 a specified number of times.
Réponse acceptée
Plus de réponses (1)
H
le 26 Mar 2014
1 commentaire
Walter Roberson
le 27 Mar 2014
semi-colon on the end of a line prevents the result of the assignment from being displayed. For example instead of
HOLD(i,j)=HNEW(i,j)
use
HOLD(i,j)=HNEW(i,j);
Catégories
En savoir plus sur Language Fundamentals dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!