## [fname,fcode] = inline (str,arg1,...) - Define a function from a string ## ## INPUT : ----------- ## str : string : String defining the result of the function ## argN : string(s) : Names of the arguments of the function ## ## OUTPUT : ---------- ## fname : string : Name of the new function, which can e.g. be called w/ ## feval() ## fcode : string : The code of the function ## ## EXAMPLE : --------- ## ## fn = inline ("x.^2 + 1","x"); ## feval (fn, 6) ## ans = 36 ## function [fname,fcode] = inline (str,varargin) ## Choose a name (naive way : won't work zillions of times) fname = blanks(18); while fname(1) == " " fname = sprintf ("inline_func_%06i",floor (rand()*1e6)); if exist (fname), fname(1) = " "; end end argstr = sprintf ("%s,",all_va_args); argstr = argstr(1:length(argstr)-1); fcode = sprintf (["function r = %s (%s)\n",\ " r = ",str,";\n",\ "endfunction;"],\ fname, argstr); eval (fcode); endfunction