% transforms a matrix into a tensor with the specified single-plane dimension; % also returns the dimensions of the new tensor function [t,tdim] = tmat2ten(a,d) if isempty(a), t = []; else if d == 1, tdim = [1 size(a)]; % 'i' matrices are stored as row vectors a = a(:)'; elseif d == 2, tdim = [size(a,1) 1 size(a,2)]; elseif d == 3, tdim = [size(a) 1]; else error('d must be between 1 and 3') end t = tzeros(tdim); t(:,1:(size(t,2)-1)) = a; end