X = randn(2,3,4);
Y = randn(2,3,4);
>> max(X,Y,3)
Error using max
MAX with two matrices to compare and a working dimension is not supported.
>> X = [1 2;3 4]
X =
1 2
3 4
>> Y = [5 6;7 8]
Y =
5 6
7 8
q=sdpvar(2,1);
objective_proxy = sdpvar;
Constraints = [norm(q,1) <= 1];
Constraints = [Constraints; max(rand(2,2,2).*repmat(q,[1 2 2]), rand(2,2,2).*repmat(q,[1 2 2])) <= objective_proxy];
Objective = objective_proxy;
sol = solvesdp(Objective,Constraints);
a = rand(2,2,2).*repmat(q,[1 2 2]);
b = rand(2,2,2).*repmat(q,[1 2 2]);
reshape(max(a(:),b(:)),size(a))
function Y = max(X,aux,workdim)
% abs (overloaded)
switch nargin
case 1
workdim = 1;
case 2
Y = max(reshape(X,[],1),reshape(aux,[],1));
Y = reshape(Y,size(X));
return
case 3
if ~isempty(aux)
error('MAX with two matrices to compare and a working dimension is not supported in MATLAB.');
end
otherwise
error('Too many input arguments')
end
xdim = size(X);
if workdim > length(xdim)
error('Index exceeds matrix dimensions.');
end
newdim = xdim;
newdim = circshift(xdim',-(workdim-1))';
newdim(1)=1;
Y = reshape(max(reshape(shiftdim(X,workdim-1),xdim(workdim),[])),newdim);
Y = shiftdim(Y,length(xdim)-workdim+1);