help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Different behaviour of function handles in matlab and octave


From: Guillem Borrell Nogueras
Subject: Different behaviour of function handles in matlab and octave
Date: Sat, 5 Nov 2005 06:19:10 -0600
User-agent: KMail/1.8.1

Hi

Playing with the interp1 function in matlab and octave i've found that the anonymous functions have different behaviours in the two interpreters.

In Matlab you can use anonymous functions to reduce the number of variables and to simplify one function, for instance:

>> x=[1 2 3 4 5 6 7 8];

>> y=[2 3 4 3 6 7 5 7];

>> newfunc=@(z) interp1(x,y,z,'spline');

>> newfunc(4.444)

ans =

4.0376

But anonymous functions in octave don't look for variables outside the function handle itself

>> x=[1 2 3 4 5 6 7 8];

>> y=[2 3 4 3 6 7 5 7];

>> newfunc=@(z) interp1(x,y,z,'spline');

>> newfunc(4.444)

error: `x' undefined near line 3 column 22

error: evaluating argument list element number 1

error: called from `?unknown?'

>>

You must define all the variables in the "heading"

>> newfunc=@(x,y,z) interp1(x,y,z,'spline');

>> newfunc(x,y,4.444)

ans = 4.0376

¿Is this a missing feature or is it a difference between the two interpreters?

thanks

guillem

--

Guillem Borrell Nogueras

WEBSITE

http://torroja.dmt.upm.es:9673/Guillem_Site/

BLOG

http://torroja.dmt.upm.es:9673/Guillem_Borrell/

EMAIL

guillemborrell_at_gmail.com (personal)

guillem_at_torroja.dmt.upm.es (CFD Lab. ETSIA)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]