function retval = bm_cellfun (x) # Vector version # retval = sin (x); # FOR loop # retval = zeros (size (x)); # for i = 1:numel (x) # retval(i) = sin (x(i)); # endfor # Arrayfun # retval = arrayfun (@sin, x); # Cellfun # retval = cellfun (@sin, x); #---------------------------------- # FOR loop w/m-file # retval = zeros (size (x)); # for i = 1:numel (x) # retval(i) = mysin (x(i)); # endfor # Arrayfun w/m-file # retval = arrayfun (@mysin, x); # Cellfun w/m-file # retval = cellfun (@mysin, x); #---------------------------------- # Cellfun w/subfunction #retval = cellfun (@mysin2, x); #---------------------------------- # Cellfun w/anonymous function # retval = cellfun (@(x) sin(x), x); #---------------------------------- # Cellfun w/inline function #retval = cellfun (inline ("sin(x)"), x); endfunction # Subfunction within same .m file function retval = mysin2(x) retval = sin (x); endfunction