Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Creation of a list of functions, multiplying functions and integrating them
Replies: 3   Last Post: Apr 25, 2013 10:48 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Steven Lord

Posts: 17,944
Registered: 12/7/04
Re: Creation of a list of functions, multiplying functions and integrating them
Posted: Apr 25, 2013 9:41 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply



"Tot " <najib_cool19@hotmail.com> wrote in message
news:klb6gs$fr5$1@newscl01ah.mathworks.com...
> Ok It's me again.
>
> I managed to multiply and integrate function handles as I wanted to.
>
> Now can anyone help me to create a list (or array) of function handle A,
> so that i can write something like:
>
> for i=1:n
> A(i)=@(x) blablabla(x)
> end
>
> Does anybody have an idea?


MATLAB no longer allow creation of arrays of function handles. You will need
to create a cell array.

S = {@sin, @(x) x.^2, @exp};
f = @(x) S{1}(x).*S{2}(x)-S{3}(x);
result1 = f(0.2)

% Alternately to get a cell array of values of the functions in S
g = @(x) cellfun(@(myfun) myfun(x), S, 'UniformOutput', false);
h = g(0:0.1:1)
h{1} % sin(0:0.1:1)
result2 = h{1}(3)*h{2}(3)-h{3}(3)

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com




Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.