help-octave
[Top][All Lists]
Advanced

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

Re: [Solved] Re: Problem with arrayfun and parameter dimensions


From: Jordi Gutiérrez Hermoso
Subject: Re: [Solved] Re: Problem with arrayfun and parameter dimensions
Date: Fri, 7 Oct 2011 11:10:36 -0500

On 7 October 2011 11:00, Christoph Mahnke <address@hidden> wrote:
>        John W. Eaton wrote:
>>
>> Do you want to apply the function for each value of X with the
>> parameters fixed for each value of X?  If so, then I think you want
>> something like
>>
>>   X = ...;
>>   parameter1 = ...;
>>   parameter2 = ...;
>>   arrayfun (@(X) dummyfunction (X, parameter1, parameter2), X);
>>
>> When the anonymous function
>>
>>   @(X) dummyfunction (X, parameter1, parameter2)
>>
>> is constructed, parameter1 and parameter2 are set from the context in
>> which the anonymous function is constructed.
>>
>> But if I understand correctly, your particular problem would probably
>> solved more efficiently by writing
>>
>>   X * (parameter1 - sum (1 ./ parameter2))
>>
>> jwe
>
>
> Thank you, this was _exactly_ the thing i was looking for.   :-)
> The dummyfunction was only an example, because the function for my
> application case is quite big and maybe confusing if the context is not
> known. But it works for it as well.
>
> I wasn't aware of the fact that the method with anonymous functions can
> be so useful.

Yeah, anonymous functions are great. They're almost closures. Their
limitation is that an anonymous function can only have one statement.
I'd like to lift this limitation, but I can't think of a good syntax
for it.

- Jordi G. H.


reply via email to

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