简体   繁体   English

八度有趣的错误-无法定义功能

[英]Octave funny error - Cannot define function

This is my code: 这是我的代码:

I get the error just after the whiles or the ifs, I don't know how to solve it. 我在片刻或ifs之后得到错误,我不知道如何解决。 Say something like: "Display all 3669 possibilities (y or n)" and starts showing and endless list of things I haven't asked for :p 说出类似的内容:“显示所有3669种可能性(y或n)”,然后开始显示无休止的清单:p

I must be defining the function wrongly but I can't find where. 我必须错误地定义了函数,但找不到位置。 It would be very helpful, If you'd told me what the problem is or how I should do to solve it. 如果您告诉我问题出在哪里或者我应该如何解决,那将非常有帮助。

R, Rer and V are vectors; R,Rer和V是向量; pc,dg and cs are numbers pc,dg和cs是数字

function [R,Rer] = er_dig(V,pc,dg,cs) 
i=0;
dg_aux=V;
while (abs(rem(dg_aux,1))!=0)
    dg_aux=dg_aux.*10;
    i++;
endwhile

Rer= (V.*dg)./100 + dg.*(10^(-i));


if (Rer<1)
    Rer_aux=Rer;
    k=0;
    while (abs(rem(Rer_aux,1))>0)
        Rer_aux=Rer_aux.*10;
        k++;
    endwhile

    if (Rer_aux>=10)
        k--;
    endif

    j=1;
    while (j<=dim(V))
        validador=(Rer(j)*(10^(k+cs))-fix(Rer(j)*(10^(k+cs-1)))*10);
        if (validador>=2)
            Rer(j) = (fix(Rer(j)*(10^(k+cs-1))) +1)/(10^(k+cs-1));
        elseif
            Rer(j) = (fix(Rer(j)*(10^(k+cs-1))))/(10^(k+cs-1));
        endif
    j++;
    endwhile


    R=V;
    i=1;
    while (i<=dim(V))
        R(i) = fix(R(i)*10^(k+cs-1))/10^(k+cs-1);
        i++;
    endwhile

elseif
    Rer_aux=Rer;
    k=0;
    while(Rer_aux>1)
        Rer_aux=Rer_aux./10;
        k++;
    endwhile


    j=1;
    while(j<=dim(V))
        validador=(Rer(j)*(10^(-k+cs))-fix(Rer(j)*(10^(-k+cs-1)))*10);
        if(validador>=2)
            Rer(j) = (fix(Rer(j)*(10^(-k+cs))) +1)/(10^(-k+cs));
        elseif
            Rer(j) = (fix(Rer(j)*(10^(k+cs))))/(10^(k+cs));
        endif
    j++;
    endwhile


    R=V;
    i=1;
    while(i<=dim(V))
        R(i) = fix(R(i)*10^(-k+cs))/10^(-k+cs);
        i++;
    endwhile

endif

endfunction 终端功能

Are you calling that from a script or copying and paste? 您是从脚本中调用还是复制粘贴? If you are copying and paste and have a double tab anywhere in your code, two tabs are for autocomplete. 如果要复制和粘贴,并且代码中的任何地方都有一个双标签,则两个标签用于自动完成。 Try to put that code in a file and call it from the Octave prompt specifying the path to the file. 尝试将该代码放入文件中,然后从Octave提示符中调用它,指定文件的路径。 Use spaces for indentation if you want to copy and paste code like that. 如果要复制和粘贴类似的代码,请使用空格作为缩进。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM