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.
You can do it like this:
map(@fib, A)
The @
makes fib
into a function handle. Note that map
is being deprecated and you should use arrayfun
instead:
arrayfun(@fib, A)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With