Thread Subject: Multiple Anonymous Functions

Subject: Multiple Anonymous Functions

From: Matthias

Date: 3 Nov, 2009 15:55:19

Message: 1 of 2

Hello,

in the Matlab Help there is an Example for Multiple Anonymous Functions:

g = @(c) (quad(@(x) (x.^2 + c*x + 1), 0, 1))

g(2)
ans =
   2.3333

This works fine. I'd like to be able to call this function with an array of parameters:
g([1,2,3])
ans =
   [g(1), g(2), g(3)]

I do not want to use external m-files and for-loops. Is there any way?

Regards,
Matthias

Subject: Multiple Anonymous Functions

From: Steve Eddins

Date: 3 Nov, 2009 16:27:31

Message: 2 of 2

Matthias wrote:
> Hello,
>
> in the Matlab Help there is an Example for Multiple Anonymous Functions:
>
> g = @(c) (quad(@(x) (x.^2 + c*x + 1), 0, 1))
>
> g(2)
> ans =
> 2.3333
>
> This works fine. I'd like to be able to call this function with an array of parameters:
> g([1,2,3])
> ans =
> [g(1), g(2), g(3)]
>
> I do not want to use external m-files and for-loops. Is there any way?
>
> Regards,
> Matthias

arrayfun

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com