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: VBA_getVolterraKernels.m
    path of file: ./repos/VBA-toolbox/core/diagnostics
    
    the code of the file until where you have to start completion: function [kernels] = VBA_getVolterraKernels(posterior,out,nt)
% Estimation of the system's 1st-order Volterra kernels
% function [my,vy,mg,vg,mx,vx] = VBA_getVolterraKernels(posterior,out)
% IN:
%   - posterior,out: the output of the VBA system inversion. Note that the
%   Volterra kernels are estimated given the input stored in out.u.
%   - nt: the maximul lag for the estimation of the Volterra kernel
% OUT:
%   - kernels: a structure, containing the fields .y, .g, .x, which refer
%   to the observed system, the simulated system observables, and the
%   simulated system hidden states. Each of these fields then contains the
%   following subfields:
%   - m: the coresponding estimated 1st-order Volterra kernels
%   - v: the estimation variance of 1st-order Volterra kernels
%   - R2: the percentage of variance explained, for each dimension

nu = size(out.u,1);
n = out.dim.n;

    
function [kernels] = VBA_getVolterraKernels(posterior,out,nt)
% Estimation of the system's 1st-order Volterra kernels
% function [my,vy,mg,vg,mx,vx] = VBA_getVolterraKernels(posterior,out)
% IN:
%   - posterior,out: the output of the VBA system inversion. Note that the
%   Volterra kernels are estimated given the input stored in out.u.
%   - nt: the maximul lag for the estimation of the Volterra kernel
% OUT:
%   - kernels: a structure, containing the fields .y, .g, .x, which refer
%   to the observed system, the simulated system observables, and the
%   simulated system hidden states. Each of these fields then contains the
%   following subfields:
%   - m: the coresponding estimated 1st-order Volterra kernels
%   - v: the estimation variance of 1st-order Volterra kernels
%   - R2: the percentage of variance explained, for each dimension

nu = size(out.u,1);
n = out.dim.n;
p = out.dim.p;
if isequal(out.dim.n_t,1) || nu < 1 || ~any(out.u(:))
    % no time series or no input
    kernels = [];
    return
end