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