function J_dcm_plot(DCM)
% Displays variables for the given DCM

% Unpack
y = DCM.y; % predicted data (symptoms)
s = DCM.s; % psychological states
x = DCM.x; % pathophysiological states
U = DCM.U; % estimated exogenous inputs
Y = DCM.Y; % empirical data

% Plot data and latent variables
% -------------------------------------------------------------------------
spm_figure('GetWin','Data and states');
spm_clf;

subplot(4,2,1:2)
imagesc(Y'); colormap gray;
ylabel('Symptom');
set(gca,'FontSize',12); title('Actual symptom scores','FontSize',14);

subplot(4,2,3:4)
imagesc(y'); colormap gray;
ylabel('Symptom');
set(gca,'FontSize',12); title('Modelled symptom scores (level 1)'); 

subplot(4,2,5)
plot3(x(:,1), x(:,2), x(:,3)); axis square;
hold on; plot3(x(1,1), x(1,2), x(1,3), '.','Color','g');
xlabel('x1');ylabel('x2');zlabel('x3');
set(gca,'FontSize',12); title('Pathophysiological states (level 2)');

subplot(4,2,6)
imagesc(s'); colormap gray;
ylabel('Symptom');
set(gca,'FontSize',12); title('Psychopathology states (level 2)');

subplot(4,2,7:8)
plot(U'); colormap gray;
set(gca,'FontSize',12); title('Modelled exogenous inputs (level 3)');

% Plot parameters
% -------------------------------------------------------------------------
spm_figure('GetWin','Parameters');
spm_clf;
subplot(3,1,1);

% Identify free parameters
idx = spm_find_pC(DCM);
pnames = spm_fieldindices(DCM.Ep,idx);

% Unpack DCM
Ep = DCM.Ep;        % posterior expected values
Vp = diag(DCM.Cp);  % posterior variance

% Limit to free parameters
Ep = spm_vec(Ep);
Ep = Ep(idx);
Vp = Vp(idx);

spm_plot_ci(Ep,diag(Vp));
set(gca,'XTickLabel',pnames,'XTick',1:length(pnames));
set(gca,'FontSize',12);
xtickangle(90);
title('Posterior expected values');