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_pca_order.m
    path of file: ./repos/spm12/toolbox/mlm
    
    the code of the file until where you have to start completion: function [M_opt,log_ev,lambda,var] = spm_pca_order (X, N)
% Model order selection for PCA   
% FORMAT [M_opt,log_ev,lambda,var] = spm_pca_order (X, N)
%
% Model order selection for PCA using Minka's approximation to model evidence
% Input can be
%     X         Data

    
function [M_opt,log_ev,lambda,var] = spm_pca_order (X, N)
% Model order selection for PCA   
% FORMAT [M_opt,log_ev,lambda,var] = spm_pca_order (X, N)
%
% Model order selection for PCA using Minka's approximation to model evidence
% Input can be
%     X         Data
% or
%    
%     X         Covariance matrix
%     N         number of samples used for computing X
%
% M_opt         Optimum number of sources
% log_ev        Log Evidence
% lambda        Eigenspectrum
% var           Estimated observation noise (at M_opt)
%
% Algorithm:
%
% T.P. Minka. Automatic choice of dimensionality for PCA. Technical Report
% 514, MIT Media Lab, Perceptual Computing Section, 2000.
%
% Evaluation:
%
% W. Penny, S. Roberts and R. Everson (2000) ICA: model order selection
% and dynamic source models. ICA: Principles and Practice, pages 299-314. 
% Cambridge University Press.
%__________________________________________________________________________
% Copyright (C) 2007-2014 Wellcome Trust Centre for Neuroimaging

% Will Penny 
% $Id: spm_pca_order.m 5962 2014-04-17 12:47:43Z spm $


if nargin == 1
    [N,d]=size(X);
    if d > N
        X=X';
        [N,d]=size(X);
    end