You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: spm_dem2dcm.m
    path of file: ./repos/spm
    
    the code of the file until where you have to start completion: function [DCM] = spm_dem2dcm(DEM,DCM)
% Reorganisation of posteriors and priors into DCM format
% FORMAT [DCM] = spm_dem2dcm(DEM)
% FORMAT [DEM] = spm_dem2dcm(DEM,DCM)
%
% DEM - structure array (hierarchicial model)
% DCM - structure array (flat model)
%
% -------------------------------------------------------------------------
%     DCM.M.pE - prior expectation of parameters

    
function [DCM] = spm_dem2dcm(DEM,DCM)
% Reorganisation of posteriors and priors into DCM format
% FORMAT [DCM] = spm_dem2dcm(DEM)
% FORMAT [DEM] = spm_dem2dcm(DEM,DCM)
%
% DEM - structure array (hierarchicial model)
% DCM - structure array (flat model)
%
% -------------------------------------------------------------------------
%     DCM.M.pE - prior expectation of parameters
%     DCM.M.pC - prior covariances of parameters
%     DCM.Ep   - posterior expectations
%     DCM.Cp   - posterior covariance
%     DCM.F   - free energy
%
% For hierarchical models (DEM.M) the first level with non-zero prior
% variance on the parameters will be extracted.
%__________________________________________________________________________

% Karl Friston
% Copyright (C) 2015-2022 Wellcome Centre for Human Neuroimaging


% check for arrays
%--------------------------------------------------------------------------
if iscell(DEM)
    for i = 1:size(DEM,1)
        for j = 1:size(DEM,2)
            if nargin < 2
                DCM{i,j}   = spm_dem2dcm(DEM{i,j});
            else
                DCM{i,j}   = spm_dem2dcm(DEM{i,j},DCM{i,j});
            end