>> x = sdpvar(3,3,3);
>> y = sdpvar(3,3,3);
>> [x y]
Multi-dimensional SDPVAR object 6x3x3
>> [x;y]
Multi-dimensional SDPVAR object 6x3x3
>> x = randn(3,3,3);
>> y = randn(3,3);
>> z=cat(3,x,y);
>> w=cat(3,y,y)
Exactly.
m = max([length(dimx) length(dimy) along]);
dimx = [dimx ones(1,m-length(dimx))];
dimy = [dimy ones(1,m-length(dimy))];
>> x = sdpvar(2,2);
>> y = sdpvar(2,2);
>> cat(3,x,y)
>> cat(3,ndsdpvar(x),ndsdpvar(y))
Multi-dimensional SDPVAR object 2x2x2
function y = cat(varargin)
%CAT (overloaded)
switch varargin{1}
case 1
y = vertcat(varargin{2:end});
case 2
y = horzcat(varargin{2:end});
otherwise
for i = 2:nargin
if isa(varargin{i},'sdpvar');
varargin{i} = ndsdpvar(varargin{i});
end
end
y = cat(varargin{:});
end
function n = ndims(X)
n = length(size(X))
z = sdpvar(length(zindex),1);
z(find(locx))=sdpvar(x(:));
z(find(locy))=sdpvar(y(:));
A = sparse(find(locx),1:prod(dimx),1,prod(zdim),prod(dimx));
B = sparse(find(locy),1:prod(dimy),1,prod(zdim),prod(dimy));
z = A*sdpvar(x(:)) + B*sdpvar(y(:));
c = arrayfun(@(~)sdpvar(3,3), zeros(5,5,5,5), 'uni', false); % Create coefficient matrix
elements = numel(c);
if elements == 1
m = c{1};
return
end
csize = size(c);
% Construct the matrix by concatenating each dimension of the cell array into
% a temporary cell array, CT
% The exterior loop iterates one time less than the number of dimensions,
% and the final dimension (dimension 1) concatenation occurs after the loops
% Loop through the cell array dimensions in reverse order to perform the
% sequential concatenations
for cdim=(length(csize)-1):-1:1
% Pre-calculated outside the next loop for efficiency
ct = cell([csize(1:cdim) 1]);
cts = size(ct);
ctsl = length(cts);
mref = {};
% Concatenate the dimension, (CDIM+1), at each element in the temporary cell
% array, CT
for mind=1:prod(cts)
[mref{1:ctsl}] = ind2sub(cts,mind);
% Treat a size [N 1] array as size [N], since this is how the indices
% are found to calculate CT
if ctsl==2 && cts(2)==1
mref = {mref{1}};
end
% Perform the concatenation along the (CDIM+1) dimension
ct{mref{:}} = cat(cdim+1,c{mref{:},:});
end
% Replace M with the new temporarily concatenated cell array, CT
c = ct;
end
% Finally, concatenate the final rows of cells into a matrix
m = cat(1,c{:});
c = sdpvar(3*ones(1,625),3*ones(1,625));
c = reshape(c,[5 5 5 5]);