123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- clc; clear; close all;
- % Note that this histogram could easily be plotted with information that is
- % available from the meta data alone. However, this script is supposed to
- % demonstrate how to easily loop through the individual files and therefore
- % takes an approach that is slightly more time consuming.
- % This script takes a few seconds. On a Late 2013 iMac with a 3.4 GHz
- % Quad-Core Intel Core i5, running Matlab 2018b it takes around 7s.
- set(0, 'DefaultLineLineWidth', 2)
- set(0,'defaultAxesFontSize', 18)
- %% specify path
- codeDir = fileparts(mfilename('fullpath'));
- mainDir = codeDir(1:find(codeDir==filesep,1,'last'));
- dataDir = [mainDir,'data',filesep];
- % add all folders with code and data to the path
- addpath(genpath(mainDir));
- param2read = {'/event_value', '/event_time'};
- events2read = {'TRIAL_start', 'TRIAL_end'};
- sun_color = [254,94,105]/255;
- igg_color = [7, 182, 75]/255;
- edg_color = [0, 169, 255]/255;
- % read in meta data
- meta_data = readtable([dataDir,'meta_data.txt']);
- monkeys = cell2mat(meta_data.monkey);
- % Prepare Figure
- figure('Color',[1,1,1],'Units','centimeters','Position',[1, 1, 56, 24]);
- experiments = {'MSTm', 'MSTt', 'MSTn'};
- for exp = 1 : length(experiments)
- % the short way would be
- % trial_total = eval(['meta_data.Exp_',experiments{exp},'_tt']);
- % but we actually want to loop through all files and load them, maybe
- % because we don't trust the information in the meta data
- trial_total = [];
- for rec = 1:height(meta_data) % loop through recording sessions
- % construct the filename
- filename = ['amm-',experiments{exp},'-',meta_data.monkey{rec},...
- '-',strip(meta_data.session_number{rec},'both','"'),'-',...
- meta_data.daily_count{rec},'-task.h5'];
- try
- file_info = h5info(filename, '/event_value');
- % extract values and times of each event
- event_value = h5_extract(filename, param2read, events2read);
- % We perform a sanity check whether the TRIAL numbers are
- % equal (this is actually done in the technical validation
- % script, but repeated here for illustrative purposes)
- if (max(event_value.TRIAL_start) == max(event_value.TRIAL_end)) & (max(event_value.TRIAL_start) == length(event_value.TRIAL_start))
- trial_total = cat(1,trial_total,max(event_value.TRIAL_start));
- else
- error('Different trial numbers for TRIAL_start and TRIAL_end or length of TRIAL_start does not equal max');
- end
- catch
- fprintf("File %s does not seem to exist.\n", filename);
- trial_total = cat(1,trial_total,0);
- end
- end
-
-
- %% plot a distribution of the trial counts across recording sessions
- subplot(1,4,exp)
- box('off')
- sun_data = trial_total(sum(monkeys=='sun',2)==3);
- igg_data = trial_total(sum(monkeys=='igg',2)==3);
- edg_data = trial_total(sum(monkeys=='edg',2)==3);
- [~,edges] = histcounts(trial_total);
- Nsun = histcounts(sun_data,edges);
- Nigg = histcounts(igg_data,edges);
- Nedg = histcounts(edg_data,edges);
- ctrs = (edges(1:end-1)+edges(2:end))/2;
- b = bar(ctrs, [ Nsun', Nigg' Nedg'],1,'stacked');
- b(1).FaceColor = sun_color;
- b(2).FaceColor = igg_color;
- b(3).FaceColor = edg_color;
- set(gca,'XTick',ctrs(1:2:length(ctrs)));
-
-
- %histogram(trial_total,'BinWidth',75);
- xlabel('Number of trials');
- if exp==1
- ylabel('Count of recording sessions');
- end
- title(experiments{exp});
-
- %xlim([0,1400]);
- end
- % add legend
- sp4 = subplot(1,4,4);
- sp4.Visible = 'off';
- hold on
- LH(1) = plot(nan, nan, '*', 'color', sun_color);
- L{1} = 'sun';
- LH(2) = plot(nan, nan, '*', 'color', igg_color);
- L{2} = 'igg';
- LH(3) = plot(nan, nan, '*', 'color', edg_color);
- L{3} = 'edg';
- legend(LH, L, 'FontSize', 20); legend('box', 'off')
- legend('Location', 'west')
|