[Scilab-users] Matrix of function pointers?

Samuel Gougeon sgougeon at free.fr
Wed Nov 28 22:54:26 CET 2012


Hello Antoine,
Le 28/11/2012 21:44, Antoine Monmayrant a écrit :
> .../...
>
> I tried to play with %fptr_c_fptr but without success.
It could depend on the container you choose. The following works well:

function  r=%fptr_c_fptr(f,g)
     r  =  tlist(["fptrL"],  f,  g)
endfunction
// ----------------------------------
function  r  =%fptrL_c_fptr(L,f)
     r  =  tlist(["fptrL"],  L(2:$),  f)
endfunction

-->L = [ disp disp disp]
  L  =
        L(1)
  fptrL
        L(2)
        L(3)
        L(4)
  

or

function  r=%fptr_c_fptr(f,g)
     r  =  list(f,  g)
endfunction
// ----------------------------------
function  r=%l_c_fptr(L,f)
     r  =  list(L(:),  f)
endfunction

-->L = [ disp disp disp]
  L  =
        L(1)
        L(2)
        L(3)

or

function  r=%fptr_c_fptr(f,g)
     c  =  cell(1,2)
     c(1).entries  =  f
     c(2).entries  =  g
     r  =  tlist("fptrL",c)
endfunction
// ----------------------------------
function  r=%fptrL_c_fptr(L,f)
     c  =  L(2)
     d  =  c.dims
     d(2)  =  int32(d(2)*1.  +1)
     setfield(2,  d,  c)
     L2  =  getfield(3,c)  // entries
     L2($+1)  =  f
     setfield(3,L2,c)
     r  =  tlist("fptrL",  L2)
endfunction

-->L = [ disp rand diag ];

-->L(2)(1)("Hello boy")
  Hello boy

-->L(2)(2)(list(2,3))
  ans  =
     0.8497452    0.8782165    0.5608486
     0.6857310    0.0683740    0.6623569

-->L(2)(3)(1:4)
  ans  =
     1.    0.    0.    0.
     0.    2.    0.    0.
     0.    0.    3.    0.
     0.    0.    0.    4.


you may also prefer using a structure array instead of a cell
as container. It should also work.

Regards
Samuel

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20121128/295ff376/attachment.htm>


More information about the users mailing list