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: CBIG_preproc_CensorQC_sort_plot.m
    path of file: ./repos/CBIG/stable_projects/preprocessing/CBIG_fMRI_Preproc2016/utilities
    
    the code of the file until where you have to start completion: function CBIG_preproc_CensorQC_sort_plot(vol1_inmask, vol_m_inmask, vol2_inmask, outliers,...
    FRAC_DIFF_inmask, CORR_inmask, outname_noext, measure_name)

% CBIG_preproc_CensorQC_sort_plot(vol1_inmask, vol_m_inmask, vol2_inmask,
% N_inmask, outliers, FRAC_DIFF_inmask, CORR_inmask, outname_noext, measure_name)
% 
% This function sorts voxels by the values of measure_name ('CORR' -
% correlation or 'FRAC_DIFF' - fractional difference). FRAC_DIFF_inmask is
% a matrix contains the unsorted values of fractional difference within a
% centain mask, like whole brain mask or grey matter mask. CORR_inmask is a
% matrix contains the unsorted values of correlation within the same mask.
% If measure_name == 'FRAC_DIFF', this function will sort FRAC_DIFF_inmask
% in ascending direction; if measure_name == 'CORR', this function will
% sort CORR_inmask in ascending direction. Then it draws the subplots of
% three timeseries of 6 voxels (ranking 0%, 20%, ..., 100%, based on the
% sorted measure). The three timeseries are: original signal, intermediate
% signal, and the final signal. For the description of these three types of
% signal, please refer to CBIG_preproc_CensorQC.m and
% CBIG_preproc_censor_wrapper.m. This step needs to plot the position of
% outlier frames, which is indicated by a vector outliers.
%
% Input:
%     - vol1_inmask: 
%       A num_voxels x num_timepoints matrix. It is the original signal
%       within a mask (whole brain mask or gray matter mask).
%
%     - vol_m_inmask: 
%       A num_voxels x num_timepoints matrix. It is the interpolated
%       intermediate volume within a mask (whole brain mask or gray matter
%       mask).
%
%     - vol2_inmask: 
%       A num_voxels x num_timepoints matrix. It is the final volume within
%       a mask (whole brain mask or gray matter mask) after censoring.
%
%     - outliers: 
%       A num_timepoints x 1 binary vector, where 1 indicates "bad" time
%       points (outliers) and 0 indicates "good" time points.
%
%     - FRAC_DIFF_inmask: 
%       a vector within length of num_voxels. It contains the unsorted
%       measurement of fractional difference within the mask.
%
%     - CORR_inmask: 
%       a vector with length of num_voxels. It contains the unsorted value
%       of correlation within the mask.
%

    
function CBIG_preproc_CensorQC_sort_plot(vol1_inmask, vol_m_inmask, vol2_inmask, outliers,...
    FRAC_DIFF_inmask, CORR_inmask, outname_noext, measure_name)

% CBIG_preproc_CensorQC_sort_plot(vol1_inmask, vol_m_inmask, vol2_inmask,
% N_inmask, outliers, FRAC_DIFF_inmask, CORR_inmask, outname_noext, measure_name)
% 
% This function sorts voxels by the values of measure_name ('CORR' -
% correlation or 'FRAC_DIFF' - fractional difference). FRAC_DIFF_inmask is
% a matrix contains the unsorted values of fractional difference within a
% centain mask, like whole brain mask or grey matter mask. CORR_inmask is a
% matrix contains the unsorted values of correlation within the same mask.
% If measure_name == 'FRAC_DIFF', this function will sort FRAC_DIFF_inmask
% in ascending direction; if measure_name == 'CORR', this function will
% sort CORR_inmask in ascending direction. Then it draws the subplots of
% three timeseries of 6 voxels (ranking 0%, 20%, ..., 100%, based on the
% sorted measure). The three timeseries are: original signal, intermediate
% signal, and the final signal. For the description of these three types of
% signal, please refer to CBIG_preproc_CensorQC.m and
% CBIG_preproc_censor_wrapper.m. This step needs to plot the position of
% outlier frames, which is indicated by a vector outliers.
%
% Input:
%     - vol1_inmask: 
%       A num_voxels x num_timepoints matrix. It is the original signal
%       within a mask (whole brain mask or gray matter mask).
%
%     - vol_m_inmask: 
%       A num_voxels x num_timepoints matrix. It is the interpolated
%       intermediate volume within a mask (whole brain mask or gray matter
%       mask).
%
%     - vol2_inmask: 
%       A num_voxels x num_timepoints matrix. It is the final volume within
%       a mask (whole brain mask or gray matter mask) after censoring.
%
%     - outliers: 
%       A num_timepoints x 1 binary vector, where 1 indicates "bad" time
%       points (outliers) and 0 indicates "good" time points.
%
%     - FRAC_DIFF_inmask: 
%       a vector within length of num_voxels. It contains the unsorted
%       measurement of fractional difference within the mask.
%
%     - CORR_inmask: 
%       a vector with length of num_voxels. It contains the unsorted value
%       of correlation within the mask.
%
%     - outname_noext: 
%       The output name (full path) for jpg files without extension. e.g.
%       'subject_dir/Sub001_Ses1/qc/Sub0001_Ses1_bld002_interp_FracDiff_whole_6plots'
%
%     - measure_name: 
%       'CORR' or 'FRAC_DIFF', determines if measure1 is correlation or
%       fractional difference. The voxels are sorted according to
%       measure_name.
%
% Example:
% CBIG_preproc_CensorQC_sort_plot(vol1_inmask, vol_m_inmask, vol2_inmask, N_inmask, outliers, ...
%     FRAC_DIFF_inmask, CORR_inmask,
%     'subject_dir/Sub001_Ses1/qc/Sub0001_Ses1_bld002_interp_FracDiff_whole_6plots', 'FRAC_DIFF') 
% CBIG_preproc_CensorQC_sort_plot(vol1_inmask, vol_m_inmask, vol2_inmask, N_inmask, outliers, ...
%     FRAC_DIFF_inmask, CORR_inmask,
%     'subject_dir/Sub001_Ses1/qc/Sub0001_Ses1_bld002_interp_FracDiff_whole_6plots', 'CORR') 
%
% Date: Jun.14, 2016
%
% Written by Jingwei Li.
% Written by CBIG under MIT license: https://github.com/ThomasYeoLab/CBIG/blob/master/LICENSE.md

%% Check input variables
if size(outliers,2) > 1
    error('Input argument ''outliers'' should be a column vector');
end

% Remove NaN
nan_index = isnan(FRAC_DIFF_inmask) | isnan(CORR_inmask);
N_inmask = sum(nan_index == 0);
FRAC_DIFF_inmask(nan_index) = [];
CORR_inmask(nan_index) = [];
vol1_inmask(nan_index, :) = [];
vol_m_inmask(nan_index, :) = [];
vol2_inmask(nan_index, :) = [];

if(strcmp(measure_name, 'FRAC_DIFF'))
    [measure_sorted, measure_ind] = sort(FRAC_DIFF_inmask, 'ascend