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_rwls_resstats.m
    path of file: ./repos/bspm/thirdparty/spm8/toolbox/rwls
    
    the code of the file until where you have to start completion: function varargout=spm_rwls_resstats(SPM,subset,movparam_name)
% function varargout=spm_rwls_resstats(SPM,subset,movparam_name)
% 
% It attempts to find the movemen parameters for each scan 
% INPUT: 
%      SPM - SPM structure estimated with the RWLS toolbox
%      subset - Subset of scans to be plotted (defaults is all) 

    
function varargout=spm_rwls_resstats(SPM,subset,movparam_name)
% function varargout=spm_rwls_resstats(SPM,subset,movparam_name)
% 
% It attempts to find the movemen parameters for each scan 
% INPUT: 
%      SPM - SPM structure estimated with the RWLS toolbox
%      subset - Subset of scans to be plotted (defaults is all) 
%      moveparam_name - Cell array of bames of movement parameter files. If not given the
%      routine will attempt to find the file from the image information in
%      the SPM structure. 
% 
% Joern Diedrichsen (j.diedrichsen@ucl.ac.uk) v.3.0
%

[Finter,Fgraph,CmdLine] = spm('FnUIsetup','Plot residual time series',0);

% determine the subset: force subset to be in range of 1:T
%-----------------------------------------------------------------------
if (~isfield(SPM,'ResStats'))
    error('SPM needs to be estmated with RWLS toolbox');
end