Thread Subject: function handle evaluation

Subject: function handle evaluation

From: abhijit

Date: 20 Nov, 2009 03:41:03

Message: 1 of 3

Hi,

lets say: f = @(x,y) sin(x*y)

i want to evaluate at x = 1, y = pi/2, All i will do f(1,pi/2) and get the correct answer.

What if a = [1 pi/2] and type f(a), then the second argument is not defined and it errors out. So, is there a way i can pass in the input argument without explicitly writing it out. I am evaluating a function handle in a for loop where the values are changing every step. The values are getting called frrom a matrix generated based on some user input. So i dont know the value apriori.

Subject: function handle evaluation

From: Matt Fig

Date: 20 Nov, 2009 03:50:20

Message: 2 of 3

f = @(x,y) sin(x*y) ;
a = [1 pi/2];

f(a(1),a(2))

Subject: function handle evaluation

From: amaren

Date: 21 Nov, 2009 02:12:08

Message: 3 of 3

hi try this
>> f=@(x)sin(x(1)*x(2))

f =
    @(x)sin(x(1)*x(2))

>> a=[1 pi/2]

a =

    1.0000 1.5708

>> f(a)

ans =

     1

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