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_ASDf_FC2doc.m
    path of file: ./repos/CBIG/stable_projects/disorder_subtypes/Tang2020_ASDFactors/step1_FC2doc
    
    the code of the file until where you have to start completion: function [Z, discretized_Z] = CBIG_ASDf_FC2doc(corr_mat, regressors, dx_info, cohort_label, output_dir, output_name)

    
function [Z, discretized_Z] = CBIG_ASDf_FC2doc(corr_mat, regressors, dx_info, cohort_label, output_dir, output_name)
% [Z, discretized_Z] = CBIG_ASDf_FC2doc(corr_mat, regressors, dx_info, cohort_label, output_dir, output_name)
% 
% Convert FC matrix to "documents" to be used as inputs to polarLDA
% model for model parameters estimation. This function will:
% 1) estimate GLM parameters with only control participants to do regression; 
% 2) compute post-regression control group mean and std for Z-normalization;
% 3) perform Z-normalization with respect to control participants;
% 4) times 10 to Z-score and discretize to integer values so that positive means 
% hyper-connectivity (with respect to controls) and negative means hypo-connectivity; 
% 5) write into documents which can be used as inputs to polarLDA model.
% 
% Input:
%     - corr_mat: 
%           MxMxN FC matrix, where M is the number of ROIs, N is the number of subjects
%     - regressors: 
%           NxV matrix, where N is the number of subjects, V is the num of
%           regressors. The subject's order should be the same as that in corr_mat 
%     - dx_info: 
%           Nx1 vector, where N is the num of subjects. This is the diagnostic information
%           of the subjects. E.g., in ABIDE: 1 represents ASD and 2 represents controls.
%           The subject's order should be the same as that in corr_mat
%     - cohort_label: 
%           Kx1 vector, where K is the number of different cohorts (assuming
%           1st entry of cohort_label represents controls). This function
%           outputs "document" for each cohort.
%           E.g., following ABIDE convention, cohort_label should be [2; 1].
%     - output_dir:
%           Absolute path to the output directory
%     - output_name: 
%           A string to be used as the prefix to the output file name
% Output:
%     - Z:
%           NxP matrix, where P = (Mx(M-1))/2 is the number of unique
%           ROI-ROI pairs. This is the Z-scores after regression and Z-normalization with
%           respect to controls.
%     - discretized_Z:
%           NxP matrix. This is discretized Z-scores and is written into
%           the output documents output_name_dx1.dat and
%           output_name_dx2.dat.
%     - output_name_dx1.dat, output_name_dx2.dat etc.:
%           "Document" of each cohort, saved in the directory specified by output_dir.
%           E.g., output_name_dx1.dat is the "document" of cohort with
%           cohort label 1 (e.g., ASD cohort in the case of ABIDE). This 
%           document can be used as an input to polarLDA model.
%     - output_name_mean_CN.mat:
%           Mean of FC data of control participants, saved in the directory
%           specified by output_dir
%     - output_name_beta_CN.mat:
%           Regression coefficients estimated from control participants,
%           saved in the directory specified by output_dir
%     - output_name_reg_CN_mean_std.mat:
%           Post-regression mean and std of control participants, saved in
%           the directory specified by output_dir
%           
% Example:
%     [Z, discretized_Z] = CBIG_ASDf_FC2doc(corr_mat, regressors, dx_info,
%     [2; 1], '~/step1_FC2doc/output/', 'step1_output')
%     This example computes the discretized Z-scores and writes into two
%     separate documents (for ASD and control cohorts, respectively)
%     in the directory '~/step1_FC2doc/output/' with prefix file name
%     'step1_output', and gives Z-scores and discretized Z-scores as outputs.
%
% Written by Siyi Tang and CBIG under MIT license: https://github.com/ThomasYeoLab/CBIG/blob/master/LICENSE.md

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