wolffd@0: function y=max_mult(A,x) wolffd@0: % MAX_MULT Like matrix multiplication, but sum gets replaced by max wolffd@0: % function y=max_mult(A,x) y(i) = max_j A(i,j) x(j) wolffd@0: wolffd@0: %X=ones(size(A,1),1) * x(:)'; % X(j,i) = x(i) wolffd@0: %y=max(A.*X, [], 2); wolffd@0: wolffd@0: % This is faster wolffd@0: if size(x,2)==1 wolffd@0: X=x*ones(1,size(A,1)); % X(i,j) = x(i) wolffd@0: y=max(A'.*X)'; wolffd@0: else wolffd@0: %this works for arbitrarily sized A and x (but is ugly, and slower than above) wolffd@0: X=repmat(x, [1 1 size(A,1)]); wolffd@0: B=repmat(A, [1 1 size(x,2)]); wolffd@0: C=permute(B,[2 3 1]); wolffd@0: y=permute(max(C.*X),[3 2 1]); wolffd@0: % this is even slower, as is using squeeze instead of permute wolffd@0: % Y=permute(X, [3 1 2]); wolffd@0: % y=permute(max(Y.*B, [], 2), [1 3 2]); wolffd@0: end