-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimebin_decoding_test.m
More file actions
1808 lines (1526 loc) · 74.2 KB
/
timebin_decoding_test.m
File metadata and controls
1808 lines (1526 loc) · 74.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
clc
clear all
close all
spike_sorting_type = '_unsorted_aligned_thr_-4.5';
%taskName = 'GraspObject_4S_Action';
%taskName = 'GraspObject_Shuffled'; % shuffled images
taskName = 'GraspObject_Varied_Size'; % varied object/aperture sizes
%taskName = 'GraspObject_GB_Images'; % for GB
%taskName = 'GraspObject_Combined'; % for Combined task
subject_id = 's2';
% Data = load('C:\Users\macthurston\OneDrive - Kaiser Permanente\CaltechData\GraspObject_project\s3\Data\IndividualFiles\GraspObject\unsorted_aligned_thr_-4.5\s3_20230803_unsorted_aligned_thr_-4.5_GraspObject');
%Data = load('C:\Users\macthurston\OneDrive - Kaiser Permanente\CaltechData\GraspObject_project\s3\Data\IndividualFiles\GraspObject\unsorted_aligned_thr_-4.5\s3_20230724_unsorted_aligned_thr_-4.5_GraspObject');
% Data = load('C:\Users\macthurston\OneDrive - Kaiser Permanente\CaltechData\GraspObject_project\s3\Data\IndividualFiles\GraspObject\unsorted_aligned_thr_-4.5\s3_20230721_unsorted_aligned_thr_-4.5_GraspObject');
Data = load(['C:\Users\macthurston\OneDrive - Kaiser Permanente\CaltechData\GraspObject_project\' subject_id '\Data\Table_' subject_id '_' taskName spike_sorting_type]);
% keyboard
Go_data = Data.Go_data;
% remove faulty sessions, if any
error_session = {};
if strcmp(subject_id, 's2')
error_session = {'20231016'};
elseif strcmp(subject_id, 's3')
error_session = {'20250212'};
elseif strcmp(subject_id, 's4')
error_session = {'20240613'};
end
if ~isempty(error_session)
condition = cellfun(@(x) strcmp(x, error_session), Go_data.session_date);
Go_data = Go_data(~condition,:);
end
if strcmp(taskName, 'GraspObject_Varied_Size')
% add Aperture Size column
sizeKeywords = ['Small', 'Medium', 'Large'];
Go_data.Aperture_Size = cell(height(Go_data),1);
% Loop through each label and extract the size information
for i = 1:height(Go_data)
% Use regular expression to find the size keyword after the last underscore
tokens = regexp(Go_data.LabelNames{i}, '_(Small|Medium|Large)$', 'tokens');
if ~isempty(tokens)
% tokens is a cell array; extract the size keyword from it
Go_data.Aperture_Size{i} = tokens{1}{1};
end
end
end
if strcmp(taskName, 'GraspObject_Combined')
Go_data.TrialType(strcmp(Go_data.TrialType, 'Unknown')) = {'Combined'}; % adds in Combined as Trial type
% add in column with Object Type for Combined trials and original trial types (H, HO, O with Associated)
% Loop through each label and extract the object information
for i = 1:height(Go_data)
% Use regular expression to find the size keyword after the last underscore
tokens = regexp(Go_data.LabelNames{i}, '_(deck|block|rod|ball)$', 'tokens');
if ~isempty(tokens)
% tokens is a cell array; extract the size keyword from it
Go_data.ObjectType{i} = tokens{1}{1};
else
Go_data.ObjectType{i} = 'Associated';
end
end
%color_info = {[.3632 .2266 .6055],[.1176 .5333 .8980],[.8471 .1059 .3765],[1 .7569 .0275]}; % Combinations task (purple at beginning)
end
brainAreas = Go_data.frPerChannel{6}; % 7 for Ripple, 6 for Blackrock
phase_time_idx = Go_data.time_phase_labels{1,1};
numPhases = numel(unique(phase_time_idx));
phaseTimeTmp = diff(phase_time_idx);
phase_changes(1) = 1;
phase_changes(2:numPhases) = find(phaseTimeTmp) + 1;
phaseNames = {'ITI', 'Planning', 'Delay', 'Action'};
% color_info = {[0.3359, 0.7031, 0.9101],[0.8984 0.6211 0],[0.8320 0.3672 0],[0.7969, 0.4726, 0.6523],[0, 0.6171, 0.4492]}; % SMG, PMV, S1, AIP, M1
color_info = {[0.3359, 0.7031, 0.9101],[0.8984 0.6211 0],[0.8320 0.3672 0],[0.7969, 0.4726, 0.6523],[0, 0.6171, 0.4492],[.9961 .6875 0]}; % SMG, PMV, S1, AIP, M1, dlPFC
sessions_all = unique(Go_data.session_date);
numSessions = numel(sessions_all);
uniqueCueTypes = {'Hand','Hand-Object','Object'};
if strcmp(taskName, 'GraspObject_Combined')
uniqueCueTypes = {'Combined','Hand','Hand-Object','Object'};
end
flagGoTrials = true;
n_regions = length(brainAreas);
num_timebins = 174;
keyboard
%% analysis and plot for all brain regions together
% Initialize storage
all_errTest_timebin_all_regions = NaN(numSessions, num_timebins, n_regions);
first_sig_idx_all = NaN(1, n_regions);
first_sig_perc_all = NaN(1, n_regions);
peak_Cue_idx_all = NaN(1, n_regions);
peak_Cue_perc_all = NaN(1, n_regions);
peak_perc_all = NaN(1, n_regions);
peak_idx_all = NaN(1, n_regions);
% Create figure
figure('units','normalized','outerposition',[0 0 0.6 0.5]);
hold on;
plot_handles = gobjects(n_regions, 1);
for n_region = [1,3,4,5,6] %1:n_regions % GB: [1,3,4,5,6]
unit_region = brainAreas{n_region};
disp(['Processing brain region: ' unit_region]);
all_errTest_timebin = NaN(numSessions, num_timebins); % Per region
for n_session = 1:numSessions
disp(['Classification session ' sessions_all{n_session} ]);
%find idx of current session day
idxThisSession = ismember(Go_data.session_date, sessions_all(n_session));
%extract data from selected brain area
if strcmp('SMG', unit_region)
SessionData = Go_data.SMG_Go(idxThisSession,:);
elseif strcmp('PMV', unit_region)
SessionData = Go_data.PMV_Go(idxThisSession,:);
elseif strcmp('S1', unit_region)
SessionData = Go_data.S1X_Go(idxThisSession,:);
elseif strcmp('M1', unit_region)
SessionData = Go_data.M1_Go(idxThisSession,:);
elseif strcmp('AIP', unit_region)
SessionData = Go_data.AIP_Go(idxThisSession,:);
elseif strcmp('dlPFC', unit_region)
SessionData = Go_data.dlPFC_Go(idxThisSession,:);
else
error([unit_region ' does not exist '])
end
% skip session days that are empty - relevant for S1 session 20230810
if isempty(SessionData{1})
continue
end
% Z-scoring => calc the mean of the FR of each unit across all trials per timebin, not per phase)
num_trials = length(SessionData);
[num_timebins, num_units] = size(SessionData{1});
% reconfigure matrix to store all trials
all_data = NaN(num_timebins,num_units,num_trials); % 174 x 63 x 142
for t = 1:num_trials
all_data(:,:,t) = SessionData{t}; % (timebins x units) for each trial
end
% Compute the mean and SD across trials
mean_fr = mean(all_data, 3); % Result is (timebins x units)
std_fr = std(all_data, 0, 3); % (timebins x units)
std_fr(std_fr == 0) = 1; % Avoid division by zero by setting std_fr to 1 where it's zero
% Z-score normalization: (X - mean) / std
z_scored_fr = (all_data - mean_fr) ./ std_fr; % (timebins x units x trials)
% Initialize the cell array
z_scored_data = cell(num_trials, 1);
% Fill the cell array with z-scored data
for t = 1:num_trials
z_scored_data{t} = z_scored_fr(:,:,t); % Extract each trial's matrix
end
%labels
sessionLabels = Go_data.GoLabels(idxThisSession,:);
%trialType
trialTypeSession = Go_data.TrialType(idxThisSession,:);
% grasp labels
graspTypeSession = Go_data.GraspType(idxThisSession,:);
% ApertureSize
%apertureSizeSession = Go_data.Aperture_Size(idxThisSession,:);
% object labels
objectTypeSession = Go_data.ObjectType(idxThisSession,:);
%get idx for Go or NoGo trials
GoNoGoidx = logical(cell2mat(Go_data.TrialCue(idxThisSession,:)));
time_phase_labels = Go_data.time_phase_labels(idxThisSession);
if flagGoTrials
%SessionData = SessionData(GoNoGoidx);
SessionData = z_scored_data(GoNoGoidx);
sessionLabels = sessionLabels(GoNoGoidx);
time_phase_labels = time_phase_labels(GoNoGoidx);
trialTypeSession = trialTypeSession(GoNoGoidx);
graspTypeSession = graspTypeSession(GoNoGoidx);
%apertureSizeSession = apertureSizeSession(GoNoGoidx);
objectTypeSession = objectTypeSession(GoNoGoidx);
else
SessionData = SessionData(~GoNoGoidx);
sessionLabels = sessionLabels(~GoNoGoidx);
time_phase_labels = time_phase_labels(~GoNoGoidx);
trialTypeSession = trialTypeSession(~GoNoGoidx);
end
% seperate data according to cue condition
unTrialType = unique(Go_data.TrialType);
% separate data according to grasp
unGraspType = unique(Go_data.GraspType);
% separate data according to object
unObjectType = unique(Go_data.ObjectType); % includes "Associated" currently
% % only keeping Small and Large
% % Define which sizes to keep
% sizesToKeep = {'Small', 'Large'};
%
% % Find indices of trials belonging to 'small' or 'large' sessions
% SLsizeIdx = ismember(apertureSizeSession, sizesToKeep);
%
% % Extract trials that correspond to 'small' or 'large' sessions
% SessionData = SessionData(SLsizeIdx);
% sessionLabels = sessionLabels(SLsizeIdx);
% time_phase_labels = time_phase_labels(SLsizeIdx);
% trialTypeSession = trialTypeSession(SLsizeIdx);
% graspTypeSession = graspTypeSession(SLsizeIdx);
% apertureSizeSession = apertureSizeSession(SLsizeIdx);
% %objectTypeSession = objectTypeSession(SLsizeIdx);
%
% % seperate data according to size
% unAperture = unique(apertureSizeSession);
% code for CMs of grasps and modalities separately
sessionLabels_modality = trialTypeSession;
sessionLabels_grasp = graspTypeSession;
%sessionLabels_size = apertureSizeSession;
sessionLabels_object = objectTypeSession;
% Convert modality labels ('Hand', 'HandObject', 'Object') to numerical values
modality_labels = {'Hand', 'Hand_Object', 'Object'}; %'Combined'
grasp_labels = {'Lateral', 'MediumWrap', 'PalmarPinch', 'Sphere3Finger'};
%size_labels = {'Small', 'Medium', 'Large'};
object_labels = {'deck','block','rod','ball'};
sessionLabels_modality_num = zeros(size(sessionLabels_modality)); % Initialize numerical labels
sessionLabels_grasp_num = zeros(size(sessionLabels_grasp));
%sessionLabels_size_num = zeros(size(sessionLabels_size));
sessionLabels_object_num = zeros(size(sessionLabels_object));
% Loop through labels and assign numerical values
for i = 1:length(modality_labels)
sessionLabels_modality_num(strcmp(sessionLabels_modality, modality_labels{i})) = i;
end
for i = 1:length(grasp_labels)
sessionLabels_grasp_num(strcmp(sessionLabels_grasp, grasp_labels{i})) = i;
end
% for i = 1:length(size_labels)
% sessionLabels_size_num(strcmp(sessionLabels_size, size_labels{i})) = i;
% end
for i = 1:length(object_labels)
sessionLabels_object_num(strcmp(sessionLabels_object, object_labels{i})) = i;
end
combinedTrialIdx = ismember(objectTypeSession, object_labels); % removes "Associated" object type trials
errTest_timebin = NaN(num_timebins, 1);
% loop through timebins
for n_bin = 1:num_timebins
% Extract data for this timebin across all trials
data_per_timebin = cell2mat(cellfun(@(x) x(n_bin, :), SessionData(combinedTrialIdx), 'UniformOutput', false)); %(combinedTrialIdx)
% Run classification
[~, errTestTmp, ~, ~, ~] = classification.LDA_classification_rep(data_per_timebin, sessionLabels_grasp_num(combinedTrialIdx), ...
'flagErrorMatrix', false, 'PCA_variance', 95, 'flagLeaveOneOut', true, 'flagRandomPerm', false); %(combinedTrialIdx)
% Store classification accuracy
errTest_timebin(n_bin) = (1 - mean(errTestTmp)) * 100;
set(gca, 'FontSize', 12);
end
% Store the classification accuracy for each session
all_errTest_timebin(n_session, :) = errTest_timebin;
end
% Store all sessions for current region
all_errTest_timebin_all_regions(:, :, n_region) = all_errTest_timebin;
% Compute stats
CI95 = utile.calculate_CI(all_errTest_timebin);
mean_acc = mean(all_errTest_timebin, 1, 'omitnan');
ci_upper = CI95(2, :);
ci_lower = CI95(1, :);
chance = 1 / numel(unGraspType) * 100;
first_sig_idx = find(mean_acc(phase_changes(2):end) + ci_lower(phase_changes(2):end) > chance, 1, 'first') + 42;
if isempty(first_sig_idx)
first_sig_idx = 1;
end
first_sig_perc = mean_acc(first_sig_idx);
[~, cue_peak_rel_idx] = max(mean_acc(phase_changes(2):phase_changes(3)));
peak_Cue_idx = phase_changes(2) + cue_peak_rel_idx - 1;
peak_Cue_perc = mean_acc(peak_Cue_idx);
[peak_perc, peak_idx] = max(mean_acc);
% Store region summary stats
first_sig_idx_all(n_region) = first_sig_idx;
first_sig_perc_all(n_region) = first_sig_perc;
peak_Cue_idx_all(n_region) = peak_Cue_idx;
peak_Cue_perc_all(n_region) = peak_Cue_perc;
peak_perc_all(n_region) = peak_perc;
peak_idx_all(n_region) = peak_idx;
% Plotting
ER = utile.shadedErrorBar(1:num_timebins, mean_acc, ci_upper, 'lineprops', '-b');
ER.mainLine.Color = color_info{n_region};
ER.mainLine.LineWidth = 2;
ER.patch.FaceColor = color_info{n_region};
ER.edge(1).LineStyle = 'none';
ER.edge(2).LineStyle = 'none';
plot_handles(n_region) = ER.mainLine;
end
% Finalize plot
for n_phase = 1:numPhases
xline(phase_changes(n_phase), 'k--', phaseNames{n_phase}, 'LineWidth', 1.5, 'FontSize', 12);
end
xlim([0 179]);
xtickangle(45);
xlabel('Timebin');
ylabel('Classification Accuracy [%]');
title('Object Classification Accuracy Over Time');
yline(chance, '--r', 'LineWidth', 1.5);
ylim([0 100]);
yticks([0 25 50 75 100]);
legend(plot_handles, brainAreas{[1,3,4,5,6]}, 'Location', 'best');
set(gca, 'FontSize', 12);
hold off;
%% TEST analysis for timing of onset and peak
% Initialize storage
all_errTest_timebin_all_regions = NaN(numSessions, num_timebins, n_regions);
all_errTest_timebin_shuf_all_regions = NaN(numSessions, num_timebins, n_regions);
first_sig_timebin_Cue_all = NaN(1, n_regions);
first_sig_perc_all = NaN(1, n_regions);
peak_Cue_timebin_all = NaN(1, n_regions);
peak_Cue_perc_all = NaN(1, n_regions);
peak_Action_timebin_all = NaN(1, n_regions);
peak_Action_perc_all = NaN(1, n_regions);
for n_region = 1 %1:n_regions % GB: [1,3,4,5,6]
unit_region = brainAreas{n_region};
disp(['Processing brain region: ' unit_region]);
all_errTest_timebin = NaN(numSessions, num_timebins); % Per region
all_errTest_timebin_shuf = NaN(numSessions, num_timebins);
for n_session = 1%:numSessions
disp(['Classification session ' sessions_all{n_session} ]);
%find idx of current session day
idxThisSession = ismember(Go_data.session_date, sessions_all(n_session));
%extract data from selected brain area
if strcmp('SMG', unit_region)
SessionData = Go_data.SMG_Go(idxThisSession,:);
elseif strcmp('PMV', unit_region)
SessionData = Go_data.PMV_Go(idxThisSession,:);
elseif strcmp('S1', unit_region)
SessionData = Go_data.S1X_Go(idxThisSession,:);
elseif strcmp('M1', unit_region)
SessionData = Go_data.M1_Go(idxThisSession,:);
elseif strcmp('AIP', unit_region)
SessionData = Go_data.AIP_Go(idxThisSession,:);
elseif strcmp('dlPFC', unit_region)
SessionData = Go_data.dlPFC_Go(idxThisSession,:);
else
error([unit_region ' does not exist '])
end
% skip session days that are empty - relevant for S1 session 20230810
if isempty(SessionData{1})
continue
end
% Z-scoring => calc the mean of the FR of each unit across all trials per timebin, not per phase)
num_trials = length(SessionData);
[num_timebins, num_units] = size(SessionData{1});
% reconfigure matrix to store all trials
all_data = NaN(num_timebins,num_units,num_trials); % 174 x 63 x 142
for t = 1:num_trials
all_data(:,:,t) = SessionData{t}; % (timebins x units) for each trial
end
% Compute the mean and SD across trials
mean_fr = mean(all_data, 3); % Result is (timebins x units)
std_fr = std(all_data, 0, 3); % (timebins x units)
std_fr(std_fr == 0) = 1; % Avoid division by zero by setting std_fr to 1 where it's zero
% Z-score normalization: (X - mean) / std
z_scored_fr = (all_data - mean_fr) ./ std_fr; % (timebins x units x trials)
% Initialize the cell array
z_scored_data = cell(num_trials, 1);
% Fill the cell array with z-scored data
for t = 1:num_trials
z_scored_data{t} = z_scored_fr(:,:,t); % Extract each trial's matrix
end
%labels
sessionLabels = Go_data.GoLabels(idxThisSession,:);
%trialType
trialTypeSession = Go_data.TrialType(idxThisSession,:);
% grasp labels
graspTypeSession = Go_data.GraspType(idxThisSession,:);
%get idx for Go or NoGo trials
GoNoGoidx = logical(cell2mat(Go_data.TrialCue(idxThisSession,:)));
time_phase_labels = Go_data.time_phase_labels(idxThisSession);
if flagGoTrials
%SessionData = SessionData(GoNoGoidx);
SessionData = z_scored_data(GoNoGoidx);
sessionLabels = sessionLabels(GoNoGoidx);
time_phase_labels = time_phase_labels(GoNoGoidx);
trialTypeSession = trialTypeSession(GoNoGoidx);
graspTypeSession = graspTypeSession(GoNoGoidx);
%apertureSizeSession = apertureSizeSession(GoNoGoidx);
%objectTypeSession = objectTypeSession(GoNoGoidx);
else
SessionData = SessionData(~GoNoGoidx);
sessionLabels = sessionLabels(~GoNoGoidx);
time_phase_labels = time_phase_labels(~GoNoGoidx);
trialTypeSession = trialTypeSession(~GoNoGoidx);
end
% seperate data according to cue condition
unTrialType = unique(Go_data.TrialType);
% separate data according to grasp
unGraspType = unique(Go_data.GraspType);
% code for CMs of grasps and modalities separately
sessionLabels_modality = trialTypeSession;
sessionLabels_grasp = graspTypeSession;
% Convert modality labels ('Hand', 'HandObject', 'Object') to numerical values
modality_labels = {'Hand', 'Hand_Object', 'Object'}; %'Combined'
grasp_labels = {'Lateral', 'MediumWrap', 'PalmarPinch', 'Sphere3Finger'};
sessionLabels_modality_num = zeros(size(sessionLabels_modality)); % Initialize numerical labels
sessionLabels_grasp_num = zeros(size(sessionLabels_grasp));
% Loop through labels and assign numerical values
for i = 1:length(modality_labels)
sessionLabels_modality_num(strcmp(sessionLabels_modality, modality_labels{i})) = i;
end
for i = 1:length(grasp_labels)
sessionLabels_grasp_num(strcmp(sessionLabels_grasp, grasp_labels{i})) = i;
end
errTest_timebin = NaN(num_timebins, 1);
% loop through Cue
for n_bin = 42:82 % 42:82 % cue 94:174 % action
% Extract data for this timebin across all trials
data_per_cue_timebins = cell2mat(cellfun(@(x) x(n_bin, :), SessionData, 'UniformOutput', false));
% Run classification
[~, errTestTmp, ~, ~, ~] = classification.LDA_classification_rep(data_per_cue_timebins, sessionLabels_grasp_num, ...
'flagErrorMatrix', false, 'PCA_variance', 95, 'flagLeaveOneOut', true, 'flagRandomPerm', false); % regular classification
% Store classification accuracy
errTest_timebin(n_bin) = (1 - mean(errTestTmp)) * 100;
% Run classification on shuffled data
[~, errTestTmp_shuf, ~, ~, ~] = classification.LDA_classification_rep(data_per_cue_timebins, sessionLabels_grasp_num, ...
'flagErrorMatrix', false, 'PCA_variance', 95, 'flagLeaveOneOut', true, 'flagRandomPerm', true); % shuffled classification
% Store shuffled classification accuracy
errTest_timebin_shuf(n_bin) = (1 - mean(errTestTmp_shuf)) * 100;
end
% Store the classification accuracy for each session
all_errTest_timebin(n_session, :) = errTest_timebin;
% Store the shuffled classification accuracy for each session
all_errTest_timebin_shuf(n_session, :) = errTest_timebin_shuf;
end
% Store all sessions for current region
all_errTest_timebin_all_regions(:, :, n_region) = all_errTest_timebin;
% Store all shuffled sessions for current region
all_errTest_timebin_shuf_all_regions(:, :, n_region) = all_errTest_timebin_shuf;
% Compute stats
CI95 = utile.calculate_CI(all_errTest_timebin);
mean_acc = mean(all_errTest_timebin, 1, 'omitnan');
ci_upper = CI95(2, :);
ci_lower = CI95(1, :);
% Compute shuffled stats
shuf_CI95 = utile.calculate_CI(all_errTest_timebin_shuf);
shuf_mean_acc = mean(all_errTest_timebin_shuf, 1, 'omitnan');
shuf_ci_upper = shuf_CI95(2, :);
shuf_ci_lower = shuf_CI95(1, :);
chance = shuf_mean_acc(phase_changes(2):phase_changes(3)) + shuf_ci_upper(phase_changes(2):phase_changes(3));
first_sig_timebin_Cue = find(mean_acc(phase_changes(2):phase_changes(3)) + ci_lower(phase_changes(2):phase_changes(3)) > chance, 1, 'first') + 42;
if isempty(first_sig_timebin_Cue)
first_sig_timebin_Cue = 1;
end
first_sig_perc = mean_acc(first_sig_timebin_Cue);
[~, cue_peak_rel_idx] = max(mean_acc(phase_changes(2):phase_changes(3)));
peak_Cue_timebin = phase_changes(2) + cue_peak_rel_idx - 1;
peak_Cue_perc = mean_acc(peak_Cue_timebin);
% Store region summary stats
first_sig_timebin_Cue_all(n_region) = first_sig_timebin_Cue;
first_sig_perc_all(n_region) = first_sig_perc;
peak_Cue_timebin_all(n_region) = peak_Cue_timebin;
peak_Cue_perc_all(n_region) = peak_Cue_perc;
end
%% Save everything to one file
goLabel = ["NoGo", "Go"];
goLabel = goLabel(flagGoTrials + 1);
%filename = "decoded_objects_per_timebin_" + taskName + "_ALL_REGIONS_LDA_" + goLabel + "_z_scored.mat";
filename = "decoded_grasps_per_timebin_" + taskName + "_ALL_REGIONS_Shuffled_LDA_" + goLabel + "_z_scored.mat"; % shuffled data
directory = ['C:\Users\macthurston\Documents\GitHub\project_grasp_object_interaction\analyzedData\' subject_id];
save(fullfile(directory, filename), ...
'all_errTest_timebin_all_regions', ...
'first_sig_idx_all', 'first_sig_perc_all', ...
'peak_Cue_idx_all', 'peak_Cue_perc_all', ...
'peak_idx_all','peak_perc_all',...
'brainAreas');
keyboard
%% analysis and plot for individual regions
%Go_data = Data.Go_data;
% remove faulty sessions, if any
error_session = {};
if strcmp(subject_id, 's2')
error_session = {'20250618'}; % remove this date bc not enough trials per grasp for object decoding per grasp
elseif strcmp(subject_id, 's3')
error_session = {'20250212'};
elseif strcmp(subject_id, 's4')
error_session = {'20240613'};
end
if ~isempty(error_session)
condition = cellfun(@(x) strcmp(x, error_session), Go_data.session_date);
Go_data = Go_data(~condition,:);
end
unit_region = 'dlPFC';
%brainAreas = Go_data.frPerChannel{6};
phase_time_idx = Go_data.time_phase_labels{1,1};
numPhases = numel(unique(phase_time_idx));
phaseTimeTmp = diff(phase_time_idx);
phase_changes(1) = 1;
phase_changes(2:numPhases) = find(phaseTimeTmp) + 1;
phaseNames = {'ITI', 'Cue', 'Delay', 'Action'};
%color_info = {[.1176 .5333 .8980],[.8471 .1059 .3765],[1 .7569 .0275]}; % Cue Conditions
%color_info = {[0.2, 0.13, 0.53], [0.067, 0.467, 0.2], [0.53, 0.8, 0.93], [0.53, 0.13, 0.33]}; % grasps: Purple, Green, Light Blue, Dark Pink
color_info = {[.3906 .5586 .9961],[.4688 .3672 .9375],[.8594 .1484 .4961],[.9922 .3789 0]}; % objects
sessions_all = unique(Go_data.session_date);
numSessions = numel(sessions_all);
uniqueCueTypes = {'Hand','Hand-Object','Object'};
if strcmp(taskName, 'GraspObject_Combined')
uniqueCueTypes = {'Combined','Hand','Hand-Object','Object'};
%color_info = {[.3632 .2266 .6055],[.1176 .5333 .8980],[.8471 .1059 .3765],[1 .7569 .0275]}; % Combinations task (purple at beginning)
end
if strcmp(taskName, 'GraspObject_Varied_Size')
% add Aperture Size column
sizeKeywords = ['Small', 'Medium', 'Large'];
Go_data.Aperture_Size = cell(height(Go_data),1);
% Loop through each label and extract the size information
for i = 1:height(Go_data)
% Use regular expression to find the size keyword after the last underscore
tokens = regexp(Go_data.LabelNames{i}, '_(Small|Medium|Large)$', 'tokens');
if ~isempty(tokens)
% tokens is a cell array; extract the size keyword from it
Go_data.Aperture_Size{i} = tokens{1}{1};
end
end
end
flagGoTrials = true;
taskSizesAll = {'Small', 'Medium', 'Large'};
graspTypesAll = {'PalmarPinch', 'MediumWrap', 'Sphere3Finger', 'Lateral'};
% Initialize a matrix to store classification accuracy for all sessions
%all_errTest_timebin = NaN(numSessions, 174);
%all_errTest_timebin = NaN(numSessions, numel(uniqueCueTypes), 174); % for sep by Cue Modality
all_errTest_timebin = NaN(numSessions, numel(graspTypesAll), 174); % for sep by Grasp
% Initialize a cell array to store confusion matrices for each phase
%confMatAllSessions = cell(numSessions,numPhases,1);
%figure(); % for CM
for n_session = 1:numSessions
disp(['Classification session ' sessions_all{n_session} ]);
%find idx of current session day
idxThisSession = ismember(Go_data.session_date, sessions_all(n_session));
%extract data from selected brain area
if strcmp('SMG', unit_region)
SessionData = Go_data.SMG_Go(idxThisSession,:);
elseif strcmp('PMV', unit_region)
SessionData = Go_data.PMV_Go(idxThisSession,:);
elseif strcmp('S1', unit_region)
SessionData = Go_data.S1X_Go(idxThisSession,:);
elseif strcmp('M1', unit_region)
SessionData = Go_data.M1_Go(idxThisSession,:);
elseif strcmp('AIP', unit_region)
SessionData = Go_data.AIP_Go(idxThisSession,:);
elseif strcmp('dlPFC', unit_region)
SessionData = Go_data.dlPFC_Go(idxThisSession,:);
else
error([unit_region ' does not exist '])
end
% skip session days that are empty - relevant for S1 session 20230810
if isempty(SessionData{1})
continue
end
% Z-scoring => calc the mean of the FR of each unit across all trials per timebin, not per phase)
num_trials = length(SessionData);
[num_timebins, num_units] = size(SessionData{1});
% reconfigure matrix to store all trials
all_data = NaN(num_timebins,num_units,num_trials); % 174 x 63 x 142
for t = 1:num_trials
all_data(:,:,t) = SessionData{t}; % (timebins x units) for each trial
end
% Compute the mean and SD across trials
mean_fr = mean(all_data, 3); % Result is (timebins x units)
std_fr = std(all_data, 0, 3); % (timebins x units)
std_fr(std_fr == 0) = 1; % Avoid division by zero by setting std_fr to 1 where it's zero
% Z-score normalization: (X - mean) / std
z_scored_fr = (all_data - mean_fr) ./ std_fr; % (timebins x units x trials)
% Initialize the cell array
z_scored_data = cell(num_trials, 1);
% Fill the cell array with z-scored data
for t = 1:num_trials
z_scored_data{t} = z_scored_fr(:,:,t); % Extract each trial's matrix
end
%labels
sessionLabels = Go_data.GoLabels(idxThisSession,:);
%trialType
trialTypeSession = Go_data.TrialType(idxThisSession,:);
% grasp labels
graspTypeSession = Go_data.GraspType(idxThisSession,:);
%AperatureSize
%apertureSizeSession = Go_data.Aperture_Size(idxThisSession,:);
% object labels
objectTypeSession = Go_data.ObjectType(idxThisSession,:);
%get idx for Go or NoGo trials
GoNoGoidx = logical(cell2mat(Go_data.TrialCue(idxThisSession,:)));
time_phase_labels = Go_data.time_phase_labels(idxThisSession);
if flagGoTrials
%SessionData = SessionData(GoNoGoidx);
SessionData = z_scored_data(GoNoGoidx);
sessionLabels = sessionLabels(GoNoGoidx);
time_phase_labels = time_phase_labels(GoNoGoidx);
trialTypeSession = trialTypeSession(GoNoGoidx);
graspTypeSession = graspTypeSession(GoNoGoidx);
%apertureSizeSession = apertureSizeSession(GoNoGoidx);
objectTypeSession = objectTypeSession(GoNoGoidx);
else
SessionData = SessionData(~GoNoGoidx);
sessionLabels = sessionLabels(~GoNoGoidx);
time_phase_labels = time_phase_labels(~GoNoGoidx);
trialTypeSession = trialTypeSession(~GoNoGoidx);
end
% seperate data according to cue condition
unTrialType = unique(Go_data.TrialType);
% separate data according to grasp
unGraspType = unique(Go_data.GraspType);
% separate data according to object
unObjectType = unique(Go_data.ObjectType);
% seperate data according to size
%unAperture = unique(Go_data.Aperture_Size);
% % only keeping Small and Large
% % Define which sizes to keep
% sizesToKeep = {'Small', 'Large'};
%
% % Find indices of trials belonging to 'small' or 'large' sessions
% SLsizeIdx = ismember(apertureSizeSession, sizesToKeep);
%
% % Extract trials that correspond to 'small' or 'large' sessions
% SessionData = SessionData(SLsizeIdx);
% sessionLabels = sessionLabels(SLsizeIdx);
% time_phase_labels = time_phase_labels(SLsizeIdx);
% trialTypeSession = trialTypeSession(SLsizeIdx);
% graspTypeSession = graspTypeSession(SLsizeIdx);
% apertureSizeSession = apertureSizeSession(SLsizeIdx);
%
% % seperate data according to size
% unAperture = unique(apertureSizeSession);
% code for CMs of grasps and modalities separately
sessionLabels_modality = trialTypeSession;
sessionLabels_grasp = graspTypeSession;
%sessionLabels_size = apertureSizeSession;
sessionLabels_object = objectTypeSession;
% Convert labels to numerical values
modality_labels = {'Hand', 'Hand_Object', 'Object'};
grasp_labels = {'Lateral', 'MediumWrap', 'PalmarPinch', 'Sphere3Finger'};
%size_labels = {'Small', 'Large'};
object_labels = {'ball','block','deck','rod'};
sessionLabels_modality_num = zeros(size(sessionLabels_modality)); % Initialize numerical labels
sessionLabels_grasp_num = zeros(size(sessionLabels_grasp));
%sessionLabels_size_num = zeros(size(sessionLabels_size));
sessionLabels_object_num = zeros(size(sessionLabels_object));
% Loop through labels and assign numerical values
for i = 1:length(modality_labels)
sessionLabels_modality_num(strcmp(sessionLabels_modality, modality_labels{i})) = i;
end
for i = 1:length(grasp_labels)
sessionLabels_grasp_num(strcmp(sessionLabels_grasp, grasp_labels{i})) = i;
end
% for i = 1:length(size_labels)
% sessionLabels_size_num(strcmp(sessionLabels_size, size_labels{i})) = i;
% end
for i = 1:length(object_labels)
sessionLabels_object_num(strcmp(sessionLabels_object, object_labels{i})) = i;
end
combinedTrialIdx = ismember(objectTypeSession, object_labels); % removes "Associated" object type trials
SessionData = SessionData(combinedTrialIdx); % get data for combined trials only
sessionLabels_object_num = sessionLabels_object_num(combinedTrialIdx);
sessionLabels_grasp_num = sessionLabels_grasp_num(combinedTrialIdx);
errTest_timebin = NaN(num_timebins, 1);
for n_type = 1:numel(object_labels)
% find idx of trial type
%trialTypeIdx = ismember(trialTypeSession, unTrialType(n_type));
%trialGraspIdx = ismember(graspTypeSession(combinedTrialIdx), unGraspType(n_type));
trialObjectIdx = ismember(objectTypeSession(combinedTrialIdx), object_labels(n_type));
% loop through timebins
for n_bin = 1:num_timebins
% Extract data for this timebin across all trials
%data_per_timebin_per_grasp = cell2mat(cellfun(@(x) x(n_bin, :), SessionData(trialGraspIdx), 'UniformOutput', false));
%data_per_timebin_per_cue = cell2mat(cellfun(@(x) x(n_bin, :), SessionData(trialTypeIdx), 'UniformOutput', false));
data_per_timebin_per_object = cell2mat(cellfun(@(x) x(n_bin, :), SessionData(trialObjectIdx), 'UniformOutput', false));
% Run classification
[~, errTestTmp, ~, ~, ~] = classification.LDA_classification_rep(data_per_timebin_per_object, sessionLabels_grasp_num(trialObjectIdx), ...
'flagErrorMatrix', false, 'PCA_variance', 95, 'flagLeaveOneOut', true);
% Store classification accuracy
errTest_timebin(n_bin) = (1 - mean(errTestTmp)) * 100;
set(gca, 'FontSize', 12);
end
% Store the classification accuracy for each session
all_errTest_timebin(n_session, n_type, :) = errTest_timebin;
end
end
% === Plot classification accuracy over time for each Trial/Grasp Type ===
figure('units','normalized','outerposition',[0 0 0.28 0.23]); % laptop: [0 0 0.46 0.37]
hold on;
% first_sig_idx = zeros(1, numel(unTrialType));
% first_sig_perc = zeros(1, numel(unTrialType));
% peak_Cue_idx = zeros(1, numel(unTrialType));
% peak_Cue_perc = zeros(1, numel(unTrialType));
% peak_perc_all = NaN(1, numel(unTrialType));
% peak_idx_all = NaN(1, numel(unTrialType));
first_sig_idx = zeros(1, numel(unGraspType));
first_sig_perc = zeros(1, numel(unGraspType));
peak_Cue_idx = zeros(1, numel(unGraspType));
peak_Cue_perc = zeros(1, numel(unGraspType));
peak_perc_all = NaN(1, numel(unGraspType));
peak_idx_all = NaN(1, numel(unGraspType));
CI95 = utile.calculate_CI(all_errTest_timebin); % (2 x numTypes x timebins)
mean_acc = squeeze(mean(all_errTest_timebin, 1, 'omitnan')); % (numTypes x timebins)
ci_upper = squeeze(CI95(2,:,:)); % (numTypes x timebins)
ci_lower = squeeze(CI95(1,:,:)); % (numTypes x timebins)
chance = 1 / numel(unGraspType) * 100;
legend_handles = gobjects(numel(unGraspType), 1); % store line handles
legend_labels = cell(numel(unGraspType), 1); % store labels
for n_type = 1:numel(unGraspType)
% Find first significant bin (Cue phase or later)
sig_search_idx = phase_changes(2):num_timebins;
sig_idx = find(mean_acc(n_type, sig_search_idx) + ci_lower(n_type, sig_search_idx) > chance, 1, 'first');
if ~isempty(sig_idx)
first_sig_idx(n_type) = sig_search_idx(sig_idx);
first_sig_perc(n_type) = mean_acc(n_type, first_sig_idx(n_type));
end
% Find peak in Cue phase
cue_range = phase_changes(2):phase_changes(3)-1;
[~, rel_peak_idx] = max(mean_acc(n_type, cue_range));
peak_Cue_idx(n_type) = cue_range(1) + rel_peak_idx - 1;
peak_Cue_perc(n_type) = mean_acc(n_type, peak_Cue_idx(n_type));
[peak_perc, peak_idx] = max(mean_acc(n_type,:));
peak_perc_all(n_type) = peak_perc;
peak_idx_all(n_type) = peak_idx;
% Plot shaded error
ER = utile.shadedErrorBar(1:num_timebins, mean_acc(n_type,:), ...
ci_upper(n_type,:), ...
'lineprops', '-','transparent', true);
ER.mainLine.Color = color_info{n_type};
ER.mainLine.LineWidth = 2;
ER.patch.FaceColor = color_info{n_type};
ER.edge(1).LineStyle = 'none';
ER.edge(2).LineStyle = 'none';
% Store for legend
legend_handles(n_type) = ER.mainLine;
%legend_labels{n_type} = uniqueCueTypes{n_type};
%legend_labels{n_type} = unGraspType{n_type};
legend_labels{n_type} = object_labels{n_type};
% % Plot first significant timepoint
% plot(first_sig_idx(n_type), first_sig_perc(n_type), 'v', ...
% 'MarkerSize', 6, 'MarkerFaceColor', color_info{n_type}, 'MarkerEdgeColor', 'k');
%
% % Plot peak timepoint
% plot(peak_Cue_idx(n_type), peak_Cue_perc(n_type), 'o', ...
% 'MarkerSize', 6, 'MarkerFaceColor', color_info{n_type}, 'MarkerEdgeColor', 'k');
end
% Add phase lines
for n_phase = 1:numPhases
xline(phase_changes(n_phase), 'k--', phaseNames{n_phase}, 'LineWidth', 1.5,'FontSize',12);
end
xlim([0 num_timebins + 1]);
ylim([0 100]);
yline(chance,'--r','LineWidth',1.5);
yticks([0 25 50 75 100]);
xlabel('Timebin');
ylabel('Classification Accuracy [%]');
title(['Grasp Classification Over Time - ' unit_region]);
legend(legend_handles, legend_labels, 'Location', 'best', 'FontSize', 12);
set(gca, 'FontSize', 12);
hold off;
% save variables
goLabel = ["NoGo", "Go"];
goLabel = goLabel(flagGoTrials + 1);
% Create the filename using the brain region and analysis type
filename = "decoded_grasps_per_timebin_per_object_" + taskName + '_' + unit_region + "_LDA_" + goLabel + "_z_scored.mat"; % when z-scoring
directory = ['C:\Users\macthurston\Documents\GitHub\project_grasp_object_interaction\analyzedData\' subject_id];
full_path = fullfile(directory, filename);
% Save the relevant variables with the dynamic filename
save(full_path, 'all_errTest_timebin','first_sig_idx','first_sig_perc','peak_Cue_idx','peak_Cue_perc','peak_idx_all','peak_perc_all');
%% load Data
goLabel = ["NoGo", "Go"];
goLabel = goLabel(flagGoTrials + 1);
directory = ['C:\Users\macthurston\Documents\GitHub\project_grasp_object_interaction\analyzedData\' subject_id];
%filename = "decoded_grasp_per_timebin_per_cue_" + taskName + '_' + unit_region + "_LDA_" + goLabel + "_z_scored.mat"; % when z-scoring
filename = "decoded_grasps_per_timebin_" + taskName + '_ALL_REGIONS' + "_LDA_" + goLabel + "_z_scored.mat";
%filename = "decoded_objects_per_timebin_" + taskName + '_ALL_REGIONS' + "_LDA_" + goLabel + "_z_scored.mat";
full_path = fullfile(directory, filename);
load(full_path);
%% load multiple so can plot variable decoding together
% load Data GRASP
goLabel = ["NoGo", "Go"];
goLabel = goLabel(flagGoTrials + 1);
directory = ['C:\Users\macthurston\Documents\GitHub\project_grasp_object_interaction\analyzedData\' subject_id];
filename = "decoded_grasps_per_timebin_" + taskName + '_ALL_REGIONS' + "_LDA_" + goLabel + "_z_scored.mat";
full_path = fullfile(directory, filename);
load(full_path);
% GRASP %
G_all_errTest_timebin_all_regions = all_errTest_timebin_all_regions;
G_first_sig_idx_all = first_sig_idx_all;
G_first_sig_perc_all = first_sig_perc_all;
G_peak_Cue_idx_all = peak_Cue_idx_all;
G_peak_Cue_perc_all = peak_Cue_perc_all;
%G_peak_perc_all = peak_perc_all; % not in original pipeline
%G_peak_idx_all = peak_idx_all;
%% load multiple so can plot variable decoding together
% load Data OBJECT/SIZE
goLabel = ["NoGo", "Go"];
goLabel = goLabel(flagGoTrials + 1);
directory = ['C:\Users\macthurston\Documents\GitHub\project_grasp_object_interaction\analyzedData\' subject_id];
filename = "decoded_sizeExtremes_per_timebin_" + taskName + '_ALL_REGIONS' + "_LDA_" + goLabel + "_z_scored.mat"; % SIZE
%filename = "decoded_objects_per_timebin_" + taskName + '_ALL_REGIONS' + "_LDA_" + goLabel + "_z_scored.mat"; % OBJECT
full_path = fullfile(directory, filename);
load(full_path);
% OBJECT/SIZE EXTREMES %
X_all_errTest_timebin_all_regions = all_errTest_timebin_all_regions;
X_first_sig_idx_all = first_sig_idx_all;
X_first_sig_perc_all = first_sig_perc_all;
X_peak_Cue_idx_all = peak_Cue_idx_all;
X_peak_Cue_perc_all = peak_Cue_perc_all;
%X_peak_perc_all = peak_perc_all; % not in original pipeline
%X_peak_idx_all = peak_idx_all;
%% load SHUFFLED to replace chance line
% load Data SHUFFLED GRASP
goLabel = ["NoGo", "Go"];
goLabel = goLabel(flagGoTrials + 1);
directory = ['C:\Users\macthurston\Documents\GitHub\project_grasp_object_interaction\analyzedData\' subject_id];
filename = "decoded_grasps_per_timebin_" + taskName + '_ALL_REGIONS_Shuffled' + "_LDA_" + goLabel + "_z_scored.mat";
full_path = fullfile(directory, filename);
load(full_path);
% SHUFFLED GRASP %
SG_all_errTest_timebin_all_regions = all_errTest_timebin_all_regions;
SG_first_sig_idx_all = first_sig_idx_all;
SG_first_sig_perc_all = first_sig_perc_all;
SG_peak_Cue_idx_all = peak_Cue_idx_all;
SG_peak_Cue_perc_all = peak_Cue_perc_all;
SG_peak_perc_all = peak_perc_all;
SG_peak_idx_all = peak_idx_all;
%% load SHUFFLED to replace chance line
% load Data SHUFFLED OBJECTS/SIZE
goLabel = ["NoGo", "Go"];
goLabel = goLabel(flagGoTrials + 1);
directory = ['C:\Users\macthurston\Documents\GitHub\project_grasp_object_interaction\analyzedData\' subject_id];
%filename = "decoded_objects_per_timebin_" + taskName + '_ALL_REGIONS_Shuffled' + "_LDA_" + goLabel + "_z_scored.mat";
filename = "decoded_sizeExtremes_per_timebin_" + taskName + '_ALL_REGIONS_Shuffled' + "_LDA_" + goLabel + "_z_scored.mat";
full_path = fullfile(directory, filename);
load(full_path);
% SHUFFLED OBJECT/SIZE %
SX_all_errTest_timebin_all_regions = all_errTest_timebin_all_regions;
SX_first_sig_idx_all = first_sig_idx_all;
SX_first_sig_perc_all = first_sig_perc_all;
SX_peak_Cue_idx_all = peak_Cue_idx_all;
SX_peak_Cue_perc_all = peak_Cue_perc_all;
SX_peak_perc_all = peak_perc_all;
SX_peak_idx_all = peak_idx_all;