execution last too long and still have not come to a conclusion!

1 vue (au cours des 30 derniers jours)
Arman Kam
Arman Kam le 24 Juil 2012
Hi, i wrote a code for earthquake hazard analysis but when i try to execute the code its like it never ends, i has been 5 hours that try to run the program with the code and it is not look like a code that is so heavy for program execution, would please help me in this?
source1=csvread('C:\Users\Arman\Desktop\Matlab\CSVread\1st source_grid_csv.csv');
site=[60.5,31.5];
Mmin=4;
DM=0.1;
c1=-1.09;
c2=0.238;
c3=-1;
c4=-0.0005;
sigma=0.15;
sumNy=zeros(1,1.5/0.01);
CellArea=0.01*112.2*0.01*96.3;
for i=1:521
for j=1:400
if source1(i,j)~=-9999;
Celldecimal=[(57.935+(j-1)*0.01),(34.108-(i-1)*0.01)];
R=acos(sin(site(1,2)*pi/180)*sin(Celldecimal(1,2)*pi/180)+cos(site(1,2)*pi/180)*cos(Celldecimal(1,2)*pi/180)*cos((Celldecimal(1,1)-site(1,1))*pi/180))*6371;
if source1(i,j)==1;
a=-1.6739;
b=0.6531;
Mmax=7.8;
Davg=17;
beta=b*log(10);
NM0=10^(a)*CellArea;
NMmin=NM0*(exp(-beta*Mmin)-exp(-beta*Mmax))/(1-exp(-beta*Mmax));
r=sqrt(R^(2)+Davg^(2));
for PGA=0.01:0.01:1.5
Nymatrix=zeros((7.9-Mmin+DM)/DM,1);
for aa=Mmin:0.1:Mmax
Mmean=aa+0.05;
Freq=NMmin*(exp(-beta*(aa-Mmin))-exp(-beta*((aa+0.1)-Mmin)))/(1-exp(-beta*(Mmax-Mmin)));
loga=log10(PGA);
logamean=c1+c2*Mmean+c3*log10(r)+c4*r;
lognormal=1-normcdf(loga,logamean,sigma);
Ny=Freq*lognormal;
if aa==Mmin
Nymatrix((aa-Mmin+DM)/DM,1)=Ny;
else
Nymatrix(round((aa-Mmin+DM)/DM),1)=Ny+Nymatrix(round((aa-Mmin)/DM),1);
end
end
sumNy(1,round(PGA/0.01))=sum(Nymatrix,1)+sumNy(1,round(PGA/0.01));
end
sorry if the code is too long but this code wont end with this part and it has 6more elseif statements and at the end it is intended to plot some values for me.
when i look through the code it doesnt seem like it is traped in an infinity loop. you will make so glad if you help me in this. Thanks
  2 commentaires
Walter Roberson
Walter Roberson le 25 Juil 2012
Consider adding a waitbar()
Also please consider adding indentation to your code! It is difficult to read the way it is, and when code is difficult to read then programmers make mistakes.
Arman Kam
Arman Kam le 25 Juil 2012
you are right dear walter, Thanks.

Connectez-vous pour commenter.

Réponse acceptée

per isakson
per isakson le 24 Juil 2012
Modifié(e) : per isakson le 25 Juil 2012
Diffucult to say why your code never ends. I doubt that the reason is in the code you show. For-loop should end eventually.
Try the following
  1. add the line "drawnow" inside the inner loop; in places you guess the code spend time
  2. start the profiler: "profile on"
  3. start your code
  4. take a cup of coffee
  5. place the cursor in the command window and press: Cntrl+C
  6. open the profiler window: "profile viewer"
try to understand what the profiler says
Maybe the code must be a function.

Plus de réponses (0)

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by