array of function handles

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

array of function handles

Francesco Potortì
How do I initialise an array with anonymous function handles?  The less
ugly I came up with is this:

      distfunction{1} = @(x,w) min(x);
      distfunction{2} = @(x,w) max(x);
      distfunction{3} = @(x,w) mediandist(x,1);
      distfunction{4} = @(x,w) mediandist(x,w);

Any better way?

--
Francesco Potortì (ricercatore)        Voice: +39 050 315 3058 (op.2111)
ISTI - Area della ricerca CNR          Fax:   +39 050 315 2040
via G. Moruzzi 1, I-56124 Pisa         Email: [hidden email]
(entrance 20, 1st floor, room C71)     Web:   http://fly.isti.cnr.it/
_______________________________________________
Help-octave mailing list
[hidden email]
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: array of function handles

David Bateman-3
Francesco Potortì wrote:

> How do I initialise an array with anonymous function handles?  The less
> ugly I came up with is this:
>
>       distfunction{1} = @(x,w) min(x);
>       distfunction{2} = @(x,w) max(x);
>       distfunction{3} = @(x,w) mediandist(x,1);
>       distfunction{4} = @(x,w) mediandist(x,w);
>
> Any better way?
>
>  
distfunction = {@(x)min(x), @(x)max(x)}

note that there is no space between the arguments as

distfunction = {@(x) min(x), @(x) max(x)}

will be treated as

distfunction = {@(x), min(x), @(x), max(x)}

by the parser, which of course is stupid.. You can protect the arguments
like

distfunction = {(@(x) min(x)), (@(x) max(x))}

permitting the spaces for readability

D.

--
David Bateman                                [hidden email]
Motorola Labs - Paris                        +33 1 69 35 48 04 (Ph)
Parc Les Algorithmes, Commune de St Aubin    +33 6 72 01 06 33 (Mob)
91193 Gif-Sur-Yvette FRANCE                  +33 1 69 35 77 01 (Fax)

The information contained in this communication has been classified as:

[x] General Business Information
[ ] Motorola Internal Use Only
[ ] Motorola Confidential Proprietary

_______________________________________________
Help-octave mailing list
[hidden email]
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: array of function handles

Francesco Potortì
>> How do I initialise an array with anonymous function handles?  The less
>> ugly I came up with is this:
>>
>>       distfunction{1} = @(x,w) min(x);
>>       distfunction{2} = @(x,w) max(x);
>>       distfunction{3} = @(x,w) mediandist(x,1);
>>       distfunction{4} = @(x,w) mediandist(x,w);
>>
>> Any better way?
>>
>>  
>distfunction = {@(x)min(x), @(x)max(x)}
>
>note that there is no space between the arguments as
>
>distfunction = {@(x) min(x), @(x) max(x)}
>
>will be treated as
>
>distfunction = {@(x), min(x), @(x), max(x)}
>
>by the parser, which of course is stupid.. You can protect the arguments
>like
>
>distfunction = {(@(x) min(x)), (@(x) max(x))}
>
>permitting the spaces for readability

Thank you.  I wonder if this should go in the manual, in which case I
could try a patch.

--
Francesco Potortì (ricercatore)        Voice: +39 050 315 3058 (op.2111)
ISTI - Area della ricerca CNR          Fax:   +39 050 315 2040
via G. Moruzzi 1, I-56124 Pisa         Email: [hidden email]
(entrance 20, 1st floor, room C71)     Web:   http://fly.isti.cnr.it/
_______________________________________________
Help-octave mailing list
[hidden email]
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave