How do I use map with custom function in Octave?
问题 Assume I have a collection A : A = [0:6:100] And I have a function fib(n) : function retval=fib(n) g1=(1+5^.5)/2 g2=(1-5^.5)/2 retval=(1/5^.5)*(g1^n - g2^n) endfunction I intend to be able to apply fib(n) on A , and store it in a collection say B, where B[i,j] is (i,fib(i)) , so I can plot i vs fib(i) and see the results on a graph. Please advise on how I can use map to obtain this desired collection B . 回答1: You can do it like this: map(@fib, A) The @ makes fib into a function handle. Note