Creating a general function handle

  • Thread starter Thread starter mikeph
  • Start date Start date
  • Tags Tags
    Function General
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
2 replies · 3K views
mikeph
Messages
1,229
Reaction score
18
I'm writing a MATLAB function m-file which has input argument of some N-by-1 vector.

Say this vector is [1,2,3].

I want to create a function handle representing a sum of x taken to the power of each number that appears in the vector, so in this case it is:

f = @(x) [x^1 + x^2 + x^3]; (x scalar)

The point is, I don't know how to define f when I don't explicitly know what the input vector is. Can anyone help me generate a general function handle? The trick is because N is variable.
 
Physics news on Phys.org
I like it! Thanks very much