简体   繁体   中英

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. Say something like: "Display all 3669 possibilities (y or n)" and starts showing and endless list of things I haven't asked for :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; pc,dg and cs are numbers

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. Use spaces for indentation if you want to copy and paste code like that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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