Undefined argument when declaring function in Octave

后端 未结 1 1727
暗喜
暗喜 2021-01-17 19:14

I get undefined variable/argument when trying to define my own random generator function.

Code:

function result = myrand(n, t, p, d)
    a = 200 * t          


        
相关标签:
1条回答
  • 2021-01-17 19:29

    You can't start a script with a function keyword. https://www.gnu.org/software/octave/doc/v4.0.1/Script-Files.html

    This works:

    disp("Running...")
    function result = myrand(n, t, p, d)
         a = 200 * t + p
         big_rand = a * n
         result = big_rand / 10**d
         return;
    endfunction
    
    mrand = myrand(5379, 0, 91, 4) 
    

    You should get:

    warning: function 'myrand' defined within script file 'myrand.m'   
    Running ...  
    a =  91  
    big_rand =  489489  
    result =  48.949  
    mrand =  48.949  
    
    0 讨论(0)
提交回复
热议问题