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
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com