view general/arrutils/mapcols.m @ 61:eff6bddf82e3 tip

Finally implemented perceptual brightness thing.
author samer
date Sun, 11 Oct 2015 10:20:42 +0100
parents fbc0540a9208
children
line wrap: on
line source
function Y=mapcols(f,X)
% mapcols - Map a function of a vector over the columns of an array
%
% mapcols :: 
%    ([[N]->A] -> [[M]->B]) ~'function maps a column of A to one of B',
%    [[N,L]->A]
% -> [[M,L]->B].

n=size(X,2);
if n==0, Y=[];
else
	y1=f(X(:,1)); 
	if size(y1,2)>1
		Y=repmat(y1(:),1,n);
		for i=2:n
			Y(:,i)=flatten(f(flatten(X(:,i))));
		end
	else
		Y=repmat(y1,1,n);
		for i=2:n, Y(:,i)=f(X(:,i)); end
	end
end