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_SEM_gen.m
    path of file: ./repos/bspm/thirdparty/spm12/toolbox/SPEM_and_DCM
    
    the code of the file until where you have to start completion: function [y,DEM] = spm_SEM_gen(P,MM,U)
% Slow/saccadic eye movement prediction scheme
% FORMAT [y,DEM] = spm_SEM_gen(P,M,U)
%
%   P - parameters
%   M - (meta) model structure
%   U - trial-specific parameter deviates
%
%   y - {[ns,nx];...} - predictions for nx states {trials}
%                     - for ns samples (normalised lag)
%
% This smooth pursuit eye movement routine generates one cycle of motion
% under prior beliefs about a sinusoidal trajectory with variable phase.
%
% see also: spm_SEM_gen_full
%__________________________________________________________________________
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging
 
% Karl Friston
% $Id: spm_SEM_gen.m 6014 2014-05-23 15:00:35Z guillaume $
 
% trial-specific initial states and parameters
%==========================================================================
if nargin > 2
    
    % cycle over different conditions

    
function [y,DEM] = spm_SEM_gen(P,MM,U)
% Slow/saccadic eye movement prediction scheme
% FORMAT [y,DEM] = spm_SEM_gen(P,M,U)
%
%   P - parameters
%   M - (meta) model structure
%   U - trial-specific parameter deviates
%
%   y - {[ns,nx];...} - predictions for nx states {trials}
%                     - for ns samples (normalised lag)
%
% This smooth pursuit eye movement routine generates one cycle of motion
% under prior beliefs about a sinusoidal trajectory with variable phase.
%
% see also: spm_SEM_gen_full
%__________________________________________________________________________
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging
 
% Karl Friston
% $Id: spm_SEM_gen.m 6014 2014-05-23 15:00:35Z guillaume $
 
% trial-specific initial states and parameters
%==========================================================================
if nargin > 2
    
    % cycle over different conditions
    %----------------------------------------------------------------------
    M       = MM;
    x       = M.x;
    [nu,nc] = size(U);
    y       = cell(1,nc);
    DEM     = cell(1,nc);
    for i = 1:nc
        
        % target location
        %------------------------------------------------------------------
        M.C   = M.u{i};
        
        % initial states
        %------------------------------------------------------------------
        M.x   = x(i);

        % condition-specific parameters (encoded in U)
        %------------------------------------------------------------------
        Q = spm_vec(P.A);
        for j = 1:nu
            Q = Q + U(j,i)*spm_vec(P.B{j});
        end