index must be a positive integer or logical.

Hi I am using matlab for earthquake hazard analysis. i have a problem with my for loop and i cant find out whats the problem.
if true
for aa=Mmin:0.1:Mmax1
Mmean1=aa+0.05;
r1=sqrt(R1^(2)+Davg1^(2));
Freq1=NMmin1*(exp(-beta1*(aa-Mmin))-exp(-beta1*((aa+0.1)-Mmin)))/(1-exp(-beta1*(Mmax1-Mmin)));
loga1=log10(PGA);
logamean1=c1+c2*Mmean1+c3*log10(r1)+c4*r1;
lognormal1=1-normcdf(loga1,logamean1,sigma);
Ny1=Freq1*lognormal1;
if aa==Mmin;
Nymatrix((aa-Mmin+DM)/DM,1)=Ny1;
elseif aa~=Mmin;
Nymatrix((aa-Mmin+DM)/DM,1)=Ny1+Nymatrix((aa-Mmin)/DM,1);
end
end
??? Attempted to access Nymatrix(1,1); index must be a positive integer or logical.
end
and also when i want to figure out what's the problem and try following code, i got this error again.
if true
for aa=Mmin:0.1:Mmax1
gg((aa-Mmin+DM)/DM,1)=aa;
??? Attempted to access gg(2,1); index must be a positive integer or logical.
end
end
please help me as soon as possible if you can. Thanks

3 件のコメント

Walter Roberson
Walter Roberson 2012 年 7 月 24 日
By the way, why do you start portions of your code with "if true" ?
Arman Kam
Arman Kam 2012 年 7 月 24 日
it is nothing important dear walter.
Jan
Jan 2012 年 7 月 24 日
Even more, Arman, it is not useful. The less confusing the posted code, the more likely is a valuable answer.

サインインしてコメントする。

 採用された回答

Titus Edelhofer
Titus Edelhofer 2012 年 7 月 24 日

1 投票

Hi,
it looks as if
(aa-Mmin+DM)/DM
is not an integer. If it should be, round would help:
gg(round((aa-Mmin+DM)/DM),1)=aa;
Titus

3 件のコメント

Arman Kam
Arman Kam 2012 年 7 月 24 日
i did as you said, but then i got this error:
??? Error using ==> round Too many input arguments.
Jan
Jan 2012 年 7 月 24 日
編集済み: Jan 2012 年 7 月 24 日
Then you have a typo in your code. Titus' line is correct.
Arman Kam
Arman Kam 2012 年 7 月 24 日
Thanks dear Titus it worked for the main code.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by