General purpose
f_save_analysis
Code
1function f_save_analysis(settings, sb, results, model_folders, plots) 2% This function saves the analysis results to the specified folder. 3% 4% Inputs: 5% - settings: The settings for the analysis. 6% - sb: The subject data. 7% - results: The results of the analysis. 8% - model_folders: The structure containing folder paths for the model. 9% - plots: The plots generated from the analysis. 10% 11% Outputs: 12% - None. The function saves the analysis data to a .mat file in the 13% specified folder. 14% 15% Used Functions: 16% - mkdir: Create a new folder if it does not exist. 17% - addpath: Add the analysis date folder to the MATLAB search path. 18% - save: Save the variables to a .mat file. 19% 20% Variables 21% Loaded: 22% - None. 23% 24% Initialized: 25% - Results_Folder: The main results folder path. 26% - Analysis_folder: The main analysis folder path. 27% - Analysis_date_folder: The folder path with the analysis date. 28% 29% Persistent: 30% - None. 31 32% Set the main results folder, analysis folder, and analysis date folder 33Results_Folder = model_folders.model.results.main; 34Analysis_folder = model_folders.model.results.analysis.main; 35Analysis_date_folder = model_folders.model.results.analysis.date.main; 36 37% Create the directories if they do not exist 38[~, ~] = mkdir(Results_Folder); 39[~, ~] = mkdir(Analysis_folder); 40[~, ~] = mkdir(Analysis_date_folder); 41 42% Add the analysis date folder to the MATLAB path 43addpath(Analysis_date_folder) 44 45% Save the analysis data to the Analysis.mat file 46try 47 save (Analysis_date_folder + "Analysis.mat", 'settings', 'sb', ... 48 'results', 'model_folders'); 49catch 50 disp("failed to save analysis"); 51end 52try 53 save (Analysis_date_folder + "Plots.mat", 'plots'); 54catch 55 disp("failed to save plots"); 56end 57end
Inputs
Outputs
Calls
Loads
f_save_plots
Code
1function f_save_plots(model_folders) 2 3Analysis_date_folder = model_folders.model.results.analysis.date.main; 4 5FigList = findobj(allchild(0), 'flat', 'Type', 'figure'); 6 7[~, ~] = mkdir(Analysis_date_folder); 8 9savefig(FigList(end: -1: 1), ... 10 Analysis_date_folder + "All_figures.fig"); 11 12for iFig = 1:length(FigList) 13 FigHandle = FigList(iFig); 14 FigName = get(FigHandle, 'Name'); 15 16 saveas(FigHandle, Analysis_date_folder + FigName + ".png") 17end 18end
Inputs
Outputs
Calls
Loads
f_get_outputs
Code
1function [n_outputs, output_names] = f_get_outputs(settings, sbtab) 2% Retrieves the total number of outputs and their names from a set of 3% experiment runs. It iterates through all the experiment runs specified in the 4% input 'stg' and, for each run, extracts the output names from the 5% corresponding dataset in 'sbtab'. It appends each output name to a cell 6% array, 'out_name', with a prefix indicating the experiment run number. 7% Finally, it returns the total number of outputs and the cell array of 8% output names. 9% 10% Inputs: 11% - stg: A structure containing experiment run indices 12% - sbtab: A structure containing datasets with output information for each 13% experiment run 14% 15% Outputs: 16% - n_outputs: The total number of outputs across all experiment runs 17% - output_names: A cell array containing the output names, prefixed with 18% the experiment run number 19% 20% Used Functions: 21% (none) 22% 23% Variables: 24% Loaded: 25% (none) 26% 27% Initialized: 28% - out_name: A cell array to store output names 29% 30% Persistent: 31% (none) 32 33% Initialize an empty cell array to store output names 34out_name = []; 35 36% Loop through all experiment runs specified in 'stg' 37for n = settings.exprun 38 % Loop through all outputs in the current experiment run 39 for j = 1:size(sbtab.datasets(n).output, 2) 40 % Add the output name to 'out_name' with a prefix indicating the 41 % experiment run 42 out_name{end + 1} = ... 43 {"E" + (n - 1) + " " + string(sbtab.datasets(n).output{1, j})}; 44 end 45end 46% Get the total number of outputs 47n_outputs = size(out_name, 2); 48 49% Assign the output names to 'output_names' 50output_names = out_name; 51end
Inputs
Outputs
Calls
Loads