This helper object saves information about the exact code that was run so that one has a record of how particular results were generated. This object gives several different methods for saving code in different files/memory configurations. The results are in a structure that has the name and path of the file being recorded, the text in the body of the file, the time when the file was last modified and the time when the log_code_object recorded the file This method inherits from the from the handle class so all logged files are persistently kept in the logged_code_structure as new files are added.


log_code_obj = log_code_object

The constructor


This method logs the file that the called this method.


If file_name is a string, this method logs the file that is in file_names, or if files_names is a cell array of strings, this method logs all the files that are in the cell array.

log_code_obj.log_files_in_directory(directory_name, file_pattern)

This method logs all the files the are in the directory directory_name that have the pattern listed in file_pattern. For example, to log all the m-files in the current directory one would use the methods: log_code_obj.log_files_in_directory('./', '*.m')

log_functions_in_memory(log_code_obj, directory_name)

This method logs all the functions that are in memory from a particular directory given in directory_name. This is particular useful if there are a large number of files in a given directory but you only want to save the ones that were used by your code (see examples below).

To get the logged information one can call the following method (or just access the field logged_code_structure):

logged_code_structure = log_code_obj.return_logged_code_structure

The number of elements in logged_code_structure is equal to the number of files logged, and the structure has the following fields:

  1. .code_filenames

    The name of the file that has been recorded.

  2. .code_filepath

    The full path to the directory where the file has been recorded.

  3. .code_body

    The text that is in the file.

  4. .last_modified_time

    The time when the file was last modified.

  5. .logged_time

    The time the file was logged (useful in case the file was changed after being logged).

  6. Example

    We recommend calling calling the method log_code_obj.log_current_file in the beginning of any code you have the specifies what decoding object/parameters are used in a data analysis (that way if you change the code while the decoding analysis is running the original parameters will be recorded). If one wants to log which functions in the Neural Decoding Toolbox were used, one can then call the log_code_obj.log_functions_in_memory(path_to_toolbox) method to save all the functions that were used. For example:

    % start of decoding scripts
    log_code_obj = log_code_object; 
    log_code_obj.log_current_file;   % log the script that is currently being run
    % create the decoding objects, run the decoding analysis with DECODING_RESULTS = cv.run_cv_decoding;
    log_code_obj.log_functions_in_memory(path_to_toolbox);  % log the functions that were used in the NDT
    decoding_code_log = log_code_obj.logged_code_structure;
    save('my_results', 'DECODING_RESULTS', 'decoding_code_log');