% multiply a tensor t by a matrix m from the right along the slices
% orthogonal to dimension d

function tnew = trightmult(t,a,d)

olddim = tdimensions(t);
newdim = olddim;
if d == 3,
  cdim = 2;
else
  cdim = 3;
end
newdim(cdim) = size(a,2);

tnew = tzeros(newdim);

for s=1:olddim(d),
  tnew = tputmatrix(tnew,s,d,tgetmatrix(t,s,d)*a);
end
