无法弄清楚Octave脚本中的语法错误

时间:2016-04-30 20:59:04

标签: matlab syntax-error octave

我不明白为什么这个错误会出现,我一直在煎我的大脑,却找不到它。错误内容为:subscript indices must be either positive integers less than 2^31 or logicals从第51行第12列调用,我将在下面的代码中标记。

我不明白为什么我的代码会解释我使用xintv4作为下标。 f2是一个函数,我称之为评估一组x值......

f2 =@(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

我尝试将for p4 = 1:2更改为for p4 = 1,并且这很有用,但是当我将循环增加到2,3或4(等)时,我就会中断。

添加了MATLAB标记,因为它们是相似的语言。

1 个答案:

答案 0 :(得分:2)

f2 = f2(xintv4)+c4;

您将匿名函数f2的返回值分配给变量 f2。第二次,f2不再是函数名称。

相关问题