2016-04-30 11 views
-1

なぜこのエラーが発生しているのかわかりません。私は脳を揚げていますが、見つけられません。エラーは、subscript indices must be either positive integers less than 2^31 or logicals行51列12から呼び出されます、私は下のコードでマークします。Octaveスクリプトで構文エラーが発生しない

私のコードが私がxintv4を添え字として使用していると解釈している理由がわかりません。 f2は関数であり、私は私がfor p4 = 1にそれを変更することにより、for p4 = 1:2で遊んでみました

f2 [email protected](x) x.^2 .* e.^(-x).*sin(pi.*x); 

a4 = -1; 
    b4 = 1; 
    c4 = 0.84685; 

    for N4 = [10]#, 100, 1000, 10000] 

     disp(""); 

     B = 1;    

     for p4 = 1:2 

     xintv4 = rand(1,N4)*2-1; 
     yintv4 = rand(1,N4)+c4; 
     f2 = f2(xintv4)+c4; #error points to this line at the "=" sign 
     nf4 = 0; 
     nf4count = 0; 
     nf4 = f2./yintv4;   

     for k = 1:N4 

       if nf4(k) >= 1 

        nf4count += 1; 

       else 

        nf4count += 0; 

       end     

     endfor 

     #disp("nf:");disp(nf); 
     #disp("nfcount:");disp(nfcount); 

     I4(p4) = ((B+c4)*(b4-a4)*(nf4count/N4))-(c4*(b4-a4));   

     endfor 

     meanI4 = mean(I4); 
     stdevI4 = std(I4); 

     disp("N = "); disp(N4); 
     disp("Mean of the integral using method 2:");disp(meanI4); 
     disp("Standard deviation of the integral using method 2:");disp(stdevI4);  

    endfor 

...それはx値のセットを評価するために呼び出すことだし、これは働いていたが、私ブレークは私が増加する場合2,3または4(等)へのループ。

MATLABタグが似た言語であるため、追加されました。

+1

最小デバッグ方法:エラーの後に 'f2(xintv4)'をテストし、次に 'f2' ... – ederag

答えて

2
f2 = f2(xintv4)+c4; 

あなたは変数f2に匿名関数f2の戻り値を割り当てます。もう一度、f2はもはや関数名ではありません。

+0

Lol woops ....それはそれでした。ありがとう! – whatwhatwhat

関連する問題