Mercurial > hg > ishara
view general/funutils/map.m @ 6:0ce3c2070089
Removed duplicate code and fixed doc in timed_action.
author | samer |
---|---|
date | Mon, 14 Jan 2013 14:33:37 +0000 |
parents | e44f49929e56 |
children | 45aaf9b2d7b0 |
line wrap: on
line source
function y=map(f,x,dim) % map - Map function over collection % % map :: (A->B), collection(A) -> collection(B). % % collection(A) ::= seq A | {D->A} | [D->A]. % % This implementation handles cell arrays and ordinary arrays. % Sequences should be taken care of by data/map if isempty(x) y=x; elseif iscell(x), y=cellmap(f,x); elseif isnumeric(x) if nargin<3, y=reshape(f(x),size(x)); elseif dim==1, y=maprows(f,x); elseif dim==2, y=mapcols(f,x); else error(sprintf('Cannot map over dimension %d',dim)); end else error(sprintf('Cannot map over objects of class %s',class(x))); end