de

% Loop over states in trajectory
for r = 1:size(xx,1)
  cost.t = r;
  if exist('j','var') && ~isempty(M{j})
    draw_pendubot(latent{j}(r,3), latent{j}(r,4), latent{j}(r,end), cost,  ...
      ['trial # ' num2str(j+J) ', T=' num2str(H*dt) ' sec'], ...
      ['total experience (after this trial): ' num2str(dt*size(x,1)) ...
      ' sec'], M{j}(:,r), Sigma{j}(:,:,r));
  else
    draw_pendubot(latent{jj}(r,3), latent{jj}(r,4), latent{jj}(r,end), cost, ...
      ['(random) trial # ' num2str(jj) ', T=' num2s