-
Notifications
You must be signed in to change notification settings - Fork 0
/
strint_rh_step2.m
1711 lines (1483 loc) · 65.6 KB
/
strint_rh_step2.m
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
% This loads in the .mat file generated in step 1
clear all
close all
% Select the subject file
str = computer;
if strcmp(str,'MACI64') == 1
cd('/Volumes/mnl/Data/Adaptation/structural_interference/Post_Step_1_test');
fname = uigetfile('*rh.mat');
fcTrials = xlsread('/Volumes/mnl/Data/Adaptation/structural_interference/Force_Channel_Trials_12_03_16.xlsx','Sheet1');
else
cd('Z:\Data\Adaptation\structural_interference\Post_Step_1_test\'); % Lab PCs
%cd('C:\Users\Alex\Desktop\IFDosing\Post_Step_1_test'); % Home PC
fname = uigetfile('*rh.mat');
fcTrials = xlsread('Z:Data\Adaptation\structural_interference\Force_Channel_Trials_12_03_16.xlsx','Sheet1'); %Lab PCs
%fcTrials = xlsread('C:\Users\Alex\Desktop\IFDosing\Force_Channel_Trials_12_03_16.xlsx','Sheet1'); % Home PC
end
load(fname);
subID = fname(1:18);
numTrials = size(sortData,1); % Number of Trials
fs = 1000; % Sample Rate (Hz)
delta_t = 1/fs; %Sample Period
% toss out trials 41 and 42, these are transition trials between
% kinesthetic and kin+rotation
wrong_trial(41) = 1;
wrong_trial(42) = 1;
channel_trial = zeros(1,numTrials);
channel_trial(fcTrials) = 1;
% Conversion between global and local reference frame (this is due to all
% x,y hand positions being referenced in the global frame, whereas the
% targets in the target table are referenced in a local frame specified in
% Deterit-E
Tx = sortData(1,1).TARGET_TABLE.X_GLOBAL(1) - sortData(1,1).TARGET_TABLE.X(1);
Ty = sortData(1,1).TARGET_TABLE.Y_GLOBAL(1) - sortData(1,1).TARGET_TABLE.Y(1);
%visual baseline, kinesthetic baseline, exposure, and post-exposure
%trial numbers in the sequence
vbTrials = 1:20;
kbTrials = 21:40;
exTrials = 43:182;
peTrials = 183:222;
rotation_type = sortData(1,1).TP_TABLE.Rotation_Type(5);
rotation_amount = sortData(1,1).TP_TABLE.Rotation_Amount(5);
theta(vbTrials) = 0; % rotation in degrees during exposure phase
theta(kbTrials) = 0;
if rotation_type == 1 && strcmp(sortData(1,1).EXPERIMENT.ACTIVE_ARM, 'RIGHT') == 1
theta(exTrials) = rotation_amount;
else
theta(exTrials) = 0;
end
theta(peTrials) = 0;
% Find the Cursor Position
% First, translate rotation point to global origin
% Then apply rotation, and translate back to target origin
cursorPosX = cell(numTrials,1);
cursorPosY = cell(numTrials,1);
handPosX = cell(numTrials,1);
handPosY = cell(numTrials,1);
for i = 1:numTrials
handPosX{i,1} = sortData(i).Right_HandX - sortData(1).TARGET_TABLE.X_GLOBAL(2)/100; % Translate to global origin
handPosY{i,1} = sortData(i).Right_HandY - sortData(1).TARGET_TABLE.Y_GLOBAL(2)/100;
cursorPosX{i,1} = handPosX{i,1}.*cosd(theta(i)) - handPosY{i,1}.*sind(theta(i)); % Reverse the rotation
cursorPosY{i,1} = handPosX{i,1}.*sind(theta(i)) + handPosY{i,1}.*cosd(theta(i));
cursorPosX{i,1} = cursorPosX{i,1} + sortData(1).TARGET_TABLE.X_GLOBAL(2)/100; % Translate back to target origin
cursorPosY{i,1} = cursorPosY{i,1} + sortData(1).TARGET_TABLE.Y_GLOBAL(2)/100;
end
% Find the "Up" and "Down" trials
upBool = zeros(numTrials,1);
for i = 1:numTrials
upBool(i) = sortData(i).TRIAL.TP == 1 || sortData(i).TRIAL.TP == 3 || sortData(i).TRIAL.TP == 5;
end
upBool = upBool';
upTrials = find(upBool == 1); % Trial numbers of "up" targets
upTrials = upTrials';
downTrials = find(upBool == 0);
downTrials = downTrials';
numDataPoints = zeros(numTrials,1);
for i = 1:numTrials
numDataPoints(i) = size(sortData(i).Right_HandX,1); % Number of Data points in each trial
end
vel = cell(numTrials,1);
velPeak = zeros(numTrials,1);
indPeak = zeros(numTrials,1);
for i = 1:numTrials
%Calculate hand speed
vel{i,1} = sqrt(sortData(i,1).Right_HandXVel.^2 + sortData(i,1).Right_HandYVel.^2);
%Find Peak velocity
if wrong_trial(i) == 0
[velPeak(i), indPeak(i)] = max(vel{i,1}(onset(i):offset(i))); % Calculates peak v for movement only
indPeak(i) = indPeak(i) + onset(i); % reindexes to start of data collection
else
velPeak(i) = NaN; indPeak(i) = NaN;
end
end
velPeakTime = indPeak - onset;
%% Movement Time (MT)
%%%%%%%%%%%%%%%%%%%%%%%%%%% Movement Time %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
MT = (offset - onset)/fs;
MT(wrong_trial==1) = NaN;
MT(channel_trial==1) = NaN;
%% MT outlier analysis
data = outlier_t(MT(upTrials(1:10))); % Outlier for visual baseline
MT_c(upTrials(1:10)) = data;
data = outlier_t(MT(downTrials(1:10)));
MT_c(downTrials(1:10)) = data;
clear data;
data = outlier_t(MT(upTrials(11:20))); % Outlier for kin baseline
MT_c(upTrials(11:20)) = data;
data = outlier_t(MT(downTrials(11:20)));
MT_c(downTrials(11:20)) = data;
clear data;
MT_c(upTrials(21)) = NaN; MT_c(downTrials(21)) = NaN; % Toss out catch trials
% data = outlier_t(MT(upTrials(14:23))); % Outlier for first 20 exposure
% MT_c(upTrials(14:23)) = data;
% data = outlier_t(MT(downTrials(14:23)));
% MT_c(downTrials(14:23)) = data;
% clear data;
MT_c(upTrials(22:31)) = MT(upTrials(22:31));
MT_c(downTrials(22:31)) = MT(downTrials(22:31));
data = outlier_t(MT(upTrials(32:91))); % Outlier for last 100 exposure
MT_c(upTrials(32:91)) = data;
data = outlier_t(MT(downTrials(32:91)));
MT_c(downTrials(32:91)) = data;
clear data;
data = outlier_t(MT(upTrials(92:96))); % Outlier for first 10 post-exp
MT_c(upTrials(92:96)) = data;
data = outlier_t(MT(downTrials(92:96)));
MT_c(downTrials(92:96)) = data;
clear data;
data = outlier_t(MT(upTrials(97:111))); % Outlier for last 10 post-exp
MT_c(upTrials(97:111)) = data;
data = outlier_t(MT(downTrials(97:111)));
MT_c(downTrials(97:111)) = data;
clear data;
% transpose and calculate standardized variable
MT_c = MT_c';
bvup_mean = nanmean(MT_c(upTrials(1:10)));
bvup_std = nanstd(MT_c(upTrials(1:10)));
MT_up_st = (MT_c(upTrials) - bvup_mean)/bvup_std;
bvdown_mean = nanmean(MT_c(downTrials(1:10)));
bvdown_std = nanstd(MT_c(downTrials(1:10)));
MT_down_st = (MT_c(downTrials) - bvdown_mean)/bvdown_std;
clear bvup_mean; clear bvup_std; clear bvdown_mean; clear bvdown_std;
%% Plotting Code for MT
figure
set(gcf,'Color','w','Position',[560 528 600 420])
hold on;
subplot('Position',[0.06 0.2 0.1 0.6]); hold on;
plot(upTrials(1:10),MT(upTrials(1:10)),'bo');
hold on
plot(upTrials(1:10),MT_c(upTrials(1:10)),'bx');
hold on
plot(downTrials(1:10),MT(downTrials(1:10)),'ro');
hold on
plot(downTrials(1:10),MT_c(downTrials(1:10)),'rx');
axis([0 20 0 6]); set(gca,'LineWidth',2,'XTick',[1 10 20],'YTick',0:1:6,'YTickLabel',0:1:6,'FontName','Arial','FontSize',10); ylabel('MT [s]'); title('vis-pre','fontsize',11);
hold on
subplot('Position',[0.19 0.2 0.1 0.6]); hold on;
plot(upTrials(11:20)-kbTrials(1)+1,MT(upTrials(11:20)),'bo');
hold on
plot(upTrials(11:20)-kbTrials(1)+1,MT_c(upTrials(11:20)),'bx');
hold on
plot(downTrials(11:20)-kbTrials(1)+1,MT(downTrials(11:20)),'ro');
hold on
plot(downTrials(11:20)-kbTrials(1)+1,MT_c(downTrials(11:20)),'rx');
axis([0 20 0 6]); set(gca,'LineWidth',2,'XTick',[1 10 20],'YTick',[],'YTickLabel',[],'FontName','Arial','FontSize',10); title('kin-pre','fontsize',11);
hold on
subplot('Position',[0.32 0.2 0.4 0.6]); hold on;
plot(upTrials(22:91)-exTrials(1)+1,MT(upTrials(22:91)),'bo');
hold on
plot(upTrials(22:91)-exTrials(1)+1,MT_c(upTrials(22:91)),'bx');
hold on
plot(downTrials(22:91)-exTrials(1)+1,MT(downTrials(22:91)),'ro');
hold on
plot(downTrials(22:91)-exTrials(1)+1,MT_c(downTrials(22:91)),'rx');
axis([0 140 0 6]); set(gca,'LineWidth',2,'XTick',[1 20 70 120 140],'YTick',[],'YTickLabel',[],'FontName','Arial','FontSize',10); title(['exposure'], 'fontsize',11); xlabel('Trials','fontsize',11);
hold on
subplot('Position',[0.75 0.2 0.24 0.6]); hold on;
plot(upTrials(92:111)-peTrials(1)+1,MT(upTrials(92:111)),'bo');
hold on
plot(upTrials(92:111)-peTrials(1)+1,MT_c(upTrials(92:111)),'bx');
hold on
plot(downTrials(92:111)-peTrials(1)+1,MT(downTrials(92:111)),'ro');
hold on
plot(downTrials(92:111)-peTrials(1)+1,MT_c(downTrials(92:111)),'rx');
axis([0 40 0 6]); set(gca,'LineWidth',2,'XTick',[1 20 40],'YTick',[],'YTickLabel',[],'FontName','Arial','FontSize',10); title(['post-exposure'], 'fontsize',11); xlabel('Trials','fontsize',11);
title('MT')
%% IDE
%%%%%%%%%%%%%%%%%%%%%%% Initial Directional Error %%%%%%%%%%%%%%%%%%%%%%%%
% Defined as the angle between the vector from hand position at movement
% onset to target position and a vector pointing to the hand
% position at peak velocity from movement onset hand position
upTargetPos = [sortData(1,1).TARGET_TABLE.X(3) sortData(1,1).TARGET_TABLE.Y(3)];
downTargetPos = [sortData(1,1).TARGET_TABLE.X(4) sortData(1,1).TARGET_TABLE.Y(4)];
xPeak = zeros(numTrials,1);
yPeak = zeros(numTrials,1);
xStart = zeros(numTrials,1);
yStart = zeros(numTrials,1);
imd = zeros(numTrials,2); % initial movement direction (x,y)
itd = zeros(numTrials,2); % initial target direction (x,y)
ide = zeros(numTrials,1);
for i = 1:numTrials
if wrong_trial(i) == 0 && channel_trial(i) == 0
% Hand Position at movement onset
xStart(i) = cursorPosX{i,1}(onset(i))*100-Tx; %in cm and workspace ref frame
yStart(i) = cursorPosY{i,1}(onset(i))*100-Ty;
% Hand Position at peak velocity
xPeak(i) = cursorPosX{i,1}(indPeak(i))*100-Tx; %in cm and workspace ref frame
yPeak(i) = cursorPosY{i,1}(indPeak(i))*100-Ty;
% Vector from start position to peak velocity position
imd(i,:) = [xPeak(i) - xStart(i) yPeak(i) - yStart(i)];
if yPeak(i) > 0
itd(i,:) = [upTargetPos(1) - xStart(i) upTargetPos(2) - yStart(i)];
elseif yPeak(i) < 0
itd(i,:) = [downTargetPos(1) - xStart(i) downTargetPos(2) - yStart(i)];
end
ide(i) = acosd(dot(itd(i,:),imd(i,:))./(norm(itd(i,:)).*norm(imd(i,:))));
% Make ide the the 1st and 3rd quad negative
if imd(i,1) > 0 && imd(i,2) > 0
ide(i) = -ide(i);
elseif imd(i,1) < 0 && imd(i,2) < 0
ide(i) = -ide(i);
end
else
xPeak(i) = NaN;
yPeak(i) = NaN;
xStart(i) = NaN;
yStart(i) = NaN;
imd(i,:) = NaN;
ide(i) = NaN;
end
end
% ide(exTrials) = ide(exTrials)-40;
%% ide outlier analysis
data = outlier_t(ide(upTrials(1:10)));
ide_c(upTrials(1:10)) = data;
data = outlier_t(ide(downTrials(1:10)));
ide_c(downTrials(1:10)) = data;
clear data;
data = outlier_t(ide(upTrials(11:20)));
ide_c(upTrials(11:20)) = data;
data = outlier_t(ide(downTrials(11:20)));
ide_c(downTrials(11:20)) = data;
clear data;
ide_c(upTrials(21)) = NaN; ide_c(downTrials(21)) = NaN;
% data = outlier_t(ide(upTrials(14:23)));
% ide_c(upTrials(14:23)) = data;
% data = outlier_t(ide(downTrials(14:23)));
% ide_c(downTrials(14:23)) = data;
% clear data;
ide_c(upTrials(22:31)) = ide(upTrials(22:31));
ide_c(downTrials(22:31)) = ide(downTrials(22:31));
data = outlier_t(ide(upTrials(32:91)));
ide_c(upTrials(32:91)) = data;
data = outlier_t(ide(downTrials(32:91)));
ide_c(downTrials(32:91)) = data;
clear data;
data = outlier_t(ide(upTrials(92:96)));
ide_c(upTrials(92:96)) = data;
data = outlier_t(ide(downTrials(92:96)));
ide_c(downTrials(92:96)) = data;
clear data;
data = outlier_t(ide(upTrials(97:111)));
ide_c(upTrials(97:111)) = data;
data = outlier_t(ide(downTrials(97:111)));
ide_c(downTrials(97:111)) = data;
clear data;
% transpose and calculate standardized variable
ide_c = ide_c';
bvup_mean = nanmean(ide_c(upTrials(1:10)));
bvup_std = nanstd(ide_c(upTrials(1:10)));
ide_up_st = (ide_c(upTrials) - bvup_mean)/bvup_std;
bvdown_mean = nanmean(ide_c(downTrials(1:10)));
bvdown_std = nanstd(ide_c(downTrials(1:10)));
ide_down_st = (ide_c(downTrials) - bvdown_mean)/bvdown_std;
clear bvup_mean; clear bvup_std; clear bvdown_mean; clear bvdown_std;
%% Plotting Code for ide
figure
set(gcf,'Color','w','Position',[560 528 600 420])
hold on;
subplot('Position',[0.06 0.2 0.1 0.6]); hold on;
plot(upTrials(1:10),ide(upTrials(1:10)),'bo');
hold on
plot(upTrials(1:10),ide_c(upTrials(1:10)),'bx');
hold on
plot(downTrials(1:10),ide(downTrials(1:10)),'ro');
hold on
plot(downTrials(1:10),ide_c(downTrials(1:10)),'rx');
axis([0 20 -80 80]); set(gca,'LineWidth',2,'XTick',[1 10 20],'YTick',-80:20:80,'YTickLabel',-80:20:80,'FontName','Arial','FontSize',10); ylabel('ide [deg]'); title('vis-pre','fontsize',11);
hold on
line([0 20],[0 0],'LineStyle','--','Color',[.5 .5 .5])
hold on
subplot('Position',[0.19 0.2 0.1 0.6]); hold on;
plot(upTrials(11:20)-kbTrials(1)+1,ide(upTrials(11:20)),'bo');
hold on
plot(upTrials(11:20)-kbTrials(1)+1,ide_c(upTrials(11:20)),'bx');
hold on
plot(downTrials(11:20)-kbTrials(1)+1,ide(downTrials(11:20)),'ro');
hold on
plot(downTrials(11:20)-kbTrials(1)+1,ide_c(downTrials(11:20)),'rx');
axis([0 20 -80 80]); set(gca,'LineWidth',2,'XTick',[1 10 20],'YTick',[],'YTickLabel',[],'FontName','Arial','FontSize',10); title('kin-pre','fontsize',11);
hold on
line([0 20],[0 0],'LineStyle','--','Color',[.5 .5 .5])
hold on
subplot('Position',[0.32 0.2 0.4 0.6]); hold on;
plot(upTrials(22:91)-exTrials(1)+1,ide(upTrials(22:91)),'bo');
hold on
plot(upTrials(22:91)-exTrials(1)+1,ide_c(upTrials(22:91)),'bx');
hold on
plot(downTrials(22:91)-exTrials(1)+1,ide(downTrials(22:91)),'ro');
hold on
plot(downTrials(22:91)-exTrials(1)+1,ide_c(downTrials(22:91)),'rx');
axis([0 140 -80 80]); set(gca,'LineWidth',2,'XTick',[1 20 70 120 140],'YTick',[],'YTickLabel',[],'FontName','Arial','FontSize',10); title(['exposure'], 'fontsize',11); xlabel('Trials','fontsize',11);
hold on
line([0 140],[0 0],'LineStyle','--','Color',[.5 .5 .5])
hold on
subplot('Position',[0.75 0.2 0.24 0.6]); hold on;
plot(upTrials(92:111)-peTrials(1)+1,ide(upTrials(92:111)),'bo');
hold on
plot(upTrials(92:111)-peTrials(1)+1,ide_c(upTrials(92:111)),'bx');
hold on
plot(downTrials(92:111)-peTrials(1)+1,ide(downTrials(92:111)),'ro');
hold on
plot(downTrials(92:111)-peTrials(1)+1,ide_c(downTrials(92:111)),'rx');
axis([0 40 -80 80]); set(gca,'LineWidth',2,'XTick',[1 20 40],'YTick',[],'YTickLabel',[],'FontName','Arial','FontSize',10); title(['post-exposure'], 'fontsize',11); xlabel('Trials','fontsize',11);
hold on
line([0 40],[0 0],'LineStyle','--','Color',[.5 .5 .5])
title('ide')
%% EDE
%%%%%%%%%%%%%%%%%%%%%%% Endpoint Directional Error %%%%%%%%%%%%%%%%%%%%%%%%
% Defined as the angle between the vector from hand position at movement
% onset to target position and a vector pointing to the hand
% position at movement endpoint from movement onset hand position
upTargetPos = [sortData(1,1).TARGET_TABLE.X(3) sortData(1,1).TARGET_TABLE.Y(3)];
downTargetPos = [sortData(1,1).TARGET_TABLE.X(4) sortData(1,1).TARGET_TABLE.Y(4)];
xOff = zeros(numTrials,1);
yOff = zeros(numTrials,1);
xStart = zeros(numTrials,1);
yStart = zeros(numTrials,1);
imd = zeros(numTrials,2); % initial movement direction (x,y)
itd = zeros(numTrials,2); % initial target direction (x,y)
ede = zeros(numTrials,1);
for i = 1:numTrials
if wrong_trial(i) == 0 && channel_trial(i) == 0
% Hand Position at movement onset
xStart(i) = cursorPosX{i,1}(onset(i))*100-Tx; %in cm and workspace ref frame
yStart(i) = cursorPosY{i,1}(onset(i))*100-Ty;
% Hand Position at peak velocity
xOff(i) = cursorPosX{i,1}(offset(i))*100-Tx; %in cm and workspace ref frame
yOff(i) = cursorPosY{i,1}(offset(i))*100-Ty;
% Vector from start position to peak velocity position
imd(i,:) = [xOff(i) - xStart(i) yOff(i) - yStart(i)];
if yOff(i) > 0
itd(i,:) = [upTargetPos(1) - xStart(i) upTargetPos(2) - yStart(i)];
elseif yOff(i) < 0
itd(i,:) = [downTargetPos(1) - xStart(i) downTargetPos(2) - yStart(i)];
end
ede(i) = acosd(dot(itd(i,:),imd(i,:))./(norm(itd(i,:)).*norm(imd(i,:))));
% Make ede the the 1st and 3rd quad negative
if imd(i,1) > 0 && imd(i,2) > 0
ede(i) = -ede(i);
elseif imd(i,1) < 0 && imd(i,2) < 0
ede(i) = -ede(i);
end
else
xOff(i) = NaN;
yOff(i) = NaN;
xStart(i) = NaN;
yStart(i) = NaN;
imd(i,:) = NaN;
ede(i) = NaN;
end
end
% ede(exTrials) = ede(exTrials)-40;
%% ede outlier analysis
data = outlier_t(ede(upTrials(1:10)));
ede_c(upTrials(1:10)) = data;
data = outlier_t(ede(downTrials(1:10)));
ede_c(downTrials(1:10)) = data;
clear data;
data = outlier_t(ede(upTrials(11:20)));
ede_c(upTrials(11:20)) = data;
data = outlier_t(ede(downTrials(11:20)));
ede_c(downTrials(11:20)) = data;
clear data;
ede_c(upTrials(21)) = NaN; ede_c(downTrials(21)) = NaN;
% data = outlier_t(ede(upTrials(14:23)));
% ede_c(upTrials(14:23)) = data;
% data = outlier_t(ede(downTrials(14:23)));
% ede_c(downTrials(14:23)) = data;
% clear data;
ede_c(upTrials(22:31)) = ede(upTrials(22:31));
ede_c(downTrials(22:31)) = ede(downTrials(22:31));
data = outlier_t(ede(upTrials(32:91)));
ede_c(upTrials(32:91)) = data;
data = outlier_t(ede(downTrials(32:91)));
ede_c(downTrials(32:91)) = data;
clear data;
data = outlier_t(ede(upTrials(92:96)));
ede_c(upTrials(92:96)) = data;
data = outlier_t(ede(downTrials(92:96)));
ede_c(downTrials(92:96)) = data;
clear data;
data = outlier_t(ede(upTrials(97:111)));
ede_c(upTrials(97:111)) = data;
data = outlier_t(ede(downTrials(97:111)));
ede_c(downTrials(97:111)) = data;
clear data;
% transpose and calculate standardized variable
ede_c = ede_c';
bvup_mean = nanmean(ede_c(upTrials(1:10)));
bvup_std = nanstd(ede_c(upTrials(1:10)));
ede_up_st = (ede_c(upTrials) - bvup_mean)/bvup_std;
bvdown_mean = nanmean(ede_c(downTrials(1:10)));
bvdown_std = nanstd(ede_c(downTrials(1:10)));
ede_down_st = (ede_c(downTrials) - bvdown_mean)/bvdown_std;
clear bvup_mean; clear bvup_std; clear bvdown_mean; clear bvdown_std;
%% Plotting Code for ede
figure
set(gcf,'Color','w','Position',[560 528 600 420])
hold on;
subplot('Position',[0.06 0.2 0.1 0.6]); hold on;
plot(upTrials(1:10),ede(upTrials(1:10)),'bo');
hold on
plot(upTrials(1:10),ede_c(upTrials(1:10)),'bx');
hold on
plot(downTrials(1:10),ede(downTrials(1:10)),'ro');
hold on
plot(downTrials(1:10),ede_c(downTrials(1:10)),'rx');
axis([0 20 -80 80]); set(gca,'LineWidth',2,'XTick',[1 10 20],'YTick',-80:20:80,'YTickLabel',-80:20:80,'FontName','Arial','FontSize',10); ylabel('ede [deg]'); title('vis-pre','fontsize',11);
hold on
line([0 20],[0 0],'LineStyle','--','Color',[.5 .5 .5])
hold on
subplot('Position',[0.19 0.2 0.1 0.6]); hold on;
plot(upTrials(11:20)-kbTrials(1)+1,ede(upTrials(11:20)),'bo');
hold on
plot(upTrials(11:20)-kbTrials(1)+1,ede_c(upTrials(11:20)),'bx');
hold on
plot(downTrials(11:20)-kbTrials(1)+1,ede(downTrials(11:20)),'ro');
hold on
plot(downTrials(11:20)-kbTrials(1)+1,ede_c(downTrials(11:20)),'rx');
axis([0 20 -80 80]); set(gca,'LineWidth',2,'XTick',[1 10 20],'YTick',[],'YTickLabel',[],'FontName','Arial','FontSize',10); title('kin-pre','fontsize',11);
hold on
line([0 20],[0 0],'LineStyle','--','Color',[.5 .5 .5])
hold on
subplot('Position',[0.32 0.2 0.4 0.6]); hold on;
plot(upTrials(22:91)-exTrials(1)+1,ede(upTrials(22:91)),'bo');
hold on
plot(upTrials(22:91)-exTrials(1)+1,ede_c(upTrials(22:91)),'bx');
hold on
plot(downTrials(22:91)-exTrials(1)+1,ede(downTrials(22:91)),'ro');
hold on
plot(downTrials(22:91)-exTrials(1)+1,ede_c(downTrials(22:91)),'rx');
axis([0 140 -80 80]); set(gca,'LineWidth',2,'XTick',[1 20 70 120 140],'YTick',[],'YTickLabel',[],'FontName','Arial','FontSize',10); title(['exposure'], 'fontsize',11); xlabel('Trials','fontsize',11);
hold on
line([0 140],[0 0],'LineStyle','--','Color',[.5 .5 .5])
hold on
subplot('Position',[0.75 0.2 0.24 0.6]); hold on;
plot(upTrials(92:111)-peTrials(1)+1,ede(upTrials(92:111)),'bo');
hold on
plot(upTrials(92:111)-peTrials(1)+1,ede_c(upTrials(92:111)),'bx');
hold on
plot(downTrials(92:111)-peTrials(1)+1,ede(downTrials(92:111)),'ro');
hold on
plot(downTrials(92:111)-peTrials(1)+1,ede_c(downTrials(92:111)),'rx');
axis([0 40 -80 80]); set(gca,'LineWidth',2,'XTick',[1 20 40],'YTick',[],'YTickLabel',[],'FontName','Arial','FontSize',10); title(['post-exposure'], 'fontsize',11); xlabel('Trials','fontsize',11);
hold on
line([0 40],[0 0],'LineStyle','--','Color',[.5 .5 .5])
title('ede')
%% RMSE
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% RMSE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Taken straight from kinsym2 step 2 files
rmse=zeros(numTrials,1); % allocate space for rmse
mov_int = zeros(numTrials,1);
for i=1:numTrials
if (wrong_trial(i)==0 && channel_trial(i)==0)
xx=cursorPosX{i,1}(onset(i):offset(i))*1000; % convert to mm
yy=cursorPosY{i,1}(onset(i):offset(i))*1000;
% spatial resampling of movement path
N= 2000; N1= length(xx); % Computes equally-spaced vector assuming 1000 samples
xc= 1/(N-1)*(0:N-1)*(xx(N1)-xx(1))+xx(1);
yc= 1/(N-1)*(0:N-1)*(yy(N1)-yy(1))+yy(1);
% integrates the movement length
mov_int(i)=sum(sqrt(diff(xx).^2+ diff(yy).^2));
di=(0:N-1)*mov_int(i)/(N-1);
d=[0; (cumsum(sqrt((diff(xx).^2)+ (diff(yy).^2))))];
% interpolates the movement path to make it equally spaced
x2i= interp1q(d,xx,di');
y2i= interp1q(d,yy,di');
x2i(N)=xc(N);
y2i(N)=yc(N);
optimal =[xc', yc'];
resampled_path =[x2i, y2i];
rmse(i) = sqrt(sum(sum((resampled_path - optimal).^2))/N);
else rmse(i)=NaN;
end
end
%% rmse outlier analysis
data = outlier_t(rmse(upTrials(1:10))); % Outlier for visual baseline
rmse_c(upTrials(1:10)) = data;
data = outlier_t(rmse(downTrials(1:10)));
rmse_c(downTrials(1:10)) = data;
clear data;
data = outlier_t(rmse(upTrials(11:20))); % Outlier for kin baseline
rmse_c(upTrials(11:20)) = data;
data = outlier_t(rmse(downTrials(11:20)));
rmse_c(downTrials(11:20)) = data;
clear data;
rmse_c(upTrials(21)) = NaN; rmse_c(downTrials(21)) = NaN; % Toss out catch trials
% data = outlier_t(rmse(upTrials(14:23))); % Outlier for first 20 exposure
% rmse_c(upTrials(14:23)) = data;
% data = outlier_t(rmse(downTrials(14:23)));
% rmse_c(downTrials(14:23)) = data;
% clear data;
rmse_c(upTrials(22:31)) = rmse(upTrials(22:31));
rmse_c(downTrials(22:31)) = rmse(downTrials(22:31));
data = outlier_t(rmse(upTrials(32:91))); % Outlier for last 100 exposure
rmse_c(upTrials(32:91)) = data;
data = outlier_t(rmse(downTrials(32:91)));
rmse_c(downTrials(32:91)) = data;
clear data;
data = outlier_t(rmse(upTrials(92:96))); % Outlier for first 10 post-exp
rmse_c(upTrials(92:96)) = data;
data = outlier_t(rmse(downTrials(92:96)));
rmse_c(downTrials(92:96)) = data;
clear data;
data = outlier_t(rmse(upTrials(97:111))); % Outlier for last 10 post-exp
rmse_c(upTrials(97:111)) = data;
data = outlier_t(rmse(downTrials(97:111)));
rmse_c(downTrials(97:111)) = data;
clear data;
% transpose and calculate standardized variable
rmse_c = rmse_c';
bvup_mean = nanmean(rmse_c(upTrials(1:10)));
bvup_std = nanstd(rmse_c(upTrials(1:10)));
rmse_up_st = (rmse_c(upTrials) - bvup_mean)/bvup_std;
bvdown_mean = nanmean(rmse_c(downTrials(1:10)));
bvdown_std = nanstd(rmse_c(downTrials(1:10)));
rmse_down_st = (rmse_c(downTrials) - bvdown_mean)/bvdown_std;
clear bvup_mean; clear bvup_std; clear bvdown_mean; clear bvdown_std;
%% Plotting Code for rmse
figure
set(gcf,'Color','w','Position',[560 528 600 420])
hold on;
subplot('Position',[0.06 0.2 0.1 0.6]); hold on;
plot(upTrials(1:10),rmse(upTrials(1:10)),'bo');
hold on
plot(upTrials(1:10),rmse_c(upTrials(1:10)),'bx');
hold on
plot(downTrials(1:10),rmse(downTrials(1:10)),'ro');
hold on
plot(downTrials(1:10),rmse_c(downTrials(1:10)),'rx');
axis([0 20 0 60]); set(gca,'LineWidth',2,'XTick',[1 10 20],'YTick',0:10:60,'YTickLabel',0:10:60,'FontName','Arial','FontSize',10); ylabel('rmse [mm]'); title('vis-pre','fontsize',11);
hold on
subplot('Position',[0.19 0.2 0.1 0.6]); hold on;
plot(upTrials(11:20)-kbTrials(1)+1,rmse(upTrials(11:20)),'bo');
hold on
plot(upTrials(11:20)-kbTrials(1)+1,rmse_c(upTrials(11:20)),'bx');
hold on
plot(downTrials(11:20)-kbTrials(1)+1,rmse(downTrials(11:20)),'ro');
hold on
plot(downTrials(11:20)-kbTrials(1)+1,rmse_c(downTrials(11:20)),'rx');
axis([0 20 0 60]); set(gca,'LineWidth',2,'XTick',[1 10 20],'YTick',[],'YTickLabel',[],'FontName','Arial','FontSize',10); title('kin-pre','fontsize',11);
hold on
subplot('Position',[0.32 0.2 0.4 0.6]); hold on;
plot(upTrials(22:91)-exTrials(1)+1,rmse(upTrials(22:91)),'bo');
hold on
plot(upTrials(22:91)-exTrials(1)+1,rmse_c(upTrials(22:91)),'bx');
hold on
plot(downTrials(22:91)-exTrials(1)+1,rmse(downTrials(22:91)),'ro');
hold on
plot(downTrials(22:91)-exTrials(1)+1,rmse_c(downTrials(22:91)),'rx');
axis([0 140 0 60]); set(gca,'LineWidth',2,'XTick',[1 20 70 120 140],'YTick',[],'YTickLabel',[],'FontName','Arial','FontSize',10); title(['exposure'], 'fontsize',11); xlabel('Trials','fontsize',11);
hold on
subplot('Position',[0.75 0.2 0.24 0.6]); hold on;
plot(upTrials(92:111)-peTrials(1)+1,rmse(upTrials(92:111)),'bo');
hold on
plot(upTrials(92:111)-peTrials(1)+1,rmse_c(upTrials(92:111)),'bx');
hold on
plot(downTrials(92:111)-peTrials(1)+1,rmse(downTrials(92:111)),'ro');
hold on
plot(downTrials(92:111)-peTrials(1)+1,rmse_c(downTrials(92:111)),'rx');
axis([0 40 0 60]); set(gca,'LineWidth',2,'XTick',[1 20 40],'YTick',[],'YTickLabel',[],'FontName','Arial','FontSize',10); title(['post-exposure'], 'fontsize',11); xlabel('Trials','fontsize',11);
title('rmse')
%% EPE, EP_X, and EP_Y calcs
%%%%%%%%%%%%%%%%%%%%%%%% End-Point Error (EPE)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% and EP_X and EP_Y
EPE = zeros(numTrials,1);
EP_X = zeros(numTrials,1);
EP_Y = zeros(numTrials,1);
for i = 1:numTrials
if wrong_trial(i) == 0 && channel_trial(i) == 0
EP_X(i) = (cursorPosX{i,1}(offset(i))*100 - Tx) - sortData(i).TARGET_TABLE.X(3);
if upBool(i) == 1
EP_Y(i) = (cursorPosY{i,1}(offset(i))*100 - Ty) - sortData(i).TARGET_TABLE.Y(3);
else
EP_Y(i) = (cursorPosY{i,1}(offset(i))*100 - Ty) - sortData(i).TARGET_TABLE.Y(4);
end
else
EPE(i) = NaN;
EP_X(i) = NaN;
EP_Y(i) = NaN;
end
end
EPE = sqrt(EP_X.^2 + EP_Y.^2);
%% EPE outlier analysis
data = outlier_t(EPE(upTrials(1:10))); % Outlier for visual baseline
EPE_c(upTrials(1:10)) = data;
data = outlier_t(EPE(downTrials(1:10)));
EPE_c(downTrials(1:10)) = data;
clear data;
data = outlier_t(EPE(upTrials(11:20))); % Outlier for kin baseline
EPE_c(upTrials(11:20)) = data;
data = outlier_t(EPE(downTrials(11:20)));
EPE_c(downTrials(11:20)) = data;
clear data;
EPE_c(upTrials(21)) = NaN; EPE_c(downTrials(21)) = NaN; % Toss out catch trials
% data = outlier_t(EPE(upTrials(14:23))); % Outlier for first 20 exposure
% EPE_c(upTrials(14:23)) = data;
% data = outlier_t(EPE(downTrials(14:23)));
% EPE_c(downTrials(14:23)) = data;
% clear data;
EPE_c(upTrials(22:31)) = EPE(upTrials(22:31));
EPE_c(downTrials(22:31)) = EPE(downTrials(22:31));
data = outlier_t(EPE(upTrials(32:91))); % Outlier for last 100 exposure
EPE_c(upTrials(32:91)) = data;
data = outlier_t(EPE(downTrials(32:91)));
EPE_c(downTrials(32:91)) = data;
clear data;
data = outlier_t(EPE(upTrials(92:96))); % Outlier for first 10 post-exp
EPE_c(upTrials(92:96)) = data;
data = outlier_t(EPE(downTrials(92:96)));
EPE_c(downTrials(92:96)) = data;
clear data;
data = outlier_t(EPE(upTrials(97:111))); % Outlier for last 10 post-exp
EPE_c(upTrials(97:111)) = data;
data = outlier_t(EPE(downTrials(97:111)));
EPE_c(downTrials(97:111)) = data;
clear data;
% transpose and calculate standardized variable
EPE_c = EPE_c';
bvup_mean = nanmean(EPE_c(upTrials(1:10)));
bvup_std = nanstd(EPE_c(upTrials(1:10)));
EPE_up_st = (EPE_c(upTrials) - bvup_mean)/bvup_std;
bvdown_mean = nanmean(EPE_c(downTrials(1:10)));
bvdown_std = nanstd(EPE_c(downTrials(1:10)));
EPE_down_st = (EPE_c(downTrials) - bvdown_mean)/bvdown_std;
clear bvup_mean; clear bvup_std; clear bvdown_mean; clear bvdown_std;
%% Plotting Code for EPE
figure
set(gcf,'Color','w','Position',[560 528 600 420])
hold on;
subplot('Position',[0.06 0.2 0.1 0.6]); hold on;
plot(upTrials(1:10),EPE(upTrials(1:10)),'bo');
hold on
plot(upTrials(1:10),EPE_c(upTrials(1:10)),'bx');
hold on
plot(downTrials(1:10),EPE(downTrials(1:10)),'ro');
hold on
plot(downTrials(1:10),EPE_c(downTrials(1:10)),'rx');
axis([0 20 0 20]); set(gca,'LineWidth',2,'XTick',[1 10 20],'YTick',0:4:20,'YTickLabel',0:4:20,'FontName','Arial','FontSize',10); ylabel('EPE [cm]'); title('vis-pre','fontsize',11);
hold on
subplot('Position',[0.19 0.2 0.1 0.6]); hold on;
plot(upTrials(11:20)-kbTrials(1)+1,EPE(upTrials(11:20)),'bo');
hold on
plot(upTrials(11:20)-kbTrials(1)+1,EPE_c(upTrials(11:20)),'bx');
hold on
plot(downTrials(11:20)-kbTrials(1)+1,EPE(downTrials(11:20)),'ro');
hold on
plot(downTrials(11:20)-kbTrials(1)+1,EPE_c(downTrials(11:20)),'rx');
axis([0 20 0 20]); set(gca,'LineWidth',2,'XTick',[1 10 20],'YTick',[],'YTickLabel',[],'FontName','Arial','FontSize',10); title('kin-pre','fontsize',11);
hold on
subplot('Position',[0.32 0.2 0.4 0.6]); hold on;
plot(upTrials(22:91)-exTrials(1)+1,EPE(upTrials(22:91)),'bo');
hold on
plot(upTrials(22:91)-exTrials(1)+1,EPE_c(upTrials(22:91)),'bx');
hold on
plot(downTrials(22:91)-exTrials(1)+1,EPE(downTrials(22:91)),'ro');
hold on
plot(downTrials(22:91)-exTrials(1)+1,EPE_c(downTrials(22:91)),'rx');
axis([0 140 0 20]); set(gca,'LineWidth',2,'XTick',[1 20 70 120 140],'YTick',[],'YTickLabel',[],'FontName','Arial','FontSize',10); title(['exposure'], 'fontsize',11); xlabel('Trials','fontsize',11);
hold on
subplot('Position',[0.75 0.2 0.24 0.6]); hold on;
plot(upTrials(92:111)-peTrials(1)+1,EPE(upTrials(92:111)),'bo');
hold on
plot(upTrials(92:111)-peTrials(1)+1,EPE_c(upTrials(92:111)),'bx');
hold on
plot(downTrials(92:111)-peTrials(1)+1,EPE(downTrials(92:111)),'ro');
hold on
plot(downTrials(92:111)-peTrials(1)+1,EPE_c(downTrials(92:111)),'rx');
axis([0 40 0 20]); set(gca,'LineWidth',2,'XTick',[1 20 40],'YTick',[],'YTickLabel',[],'FontName','Arial','FontSize',10); title(['post-exposure'], 'fontsize',11); xlabel('Trials','fontsize',11);
title('EPE')
%% EP_X outlier analysis
data = outlier_t(EP_X(upTrials(1:10))); % Outlier for visual baseline
EP_X_c(upTrials(1:10)) = data;
data = outlier_t(EP_X(downTrials(1:10)));
EP_X_c(downTrials(1:10)) = data;
clear data;
data = outlier_t(EP_X(upTrials(11:20))); % Outlier for kin baseline
EP_X_c(upTrials(11:20)) = data;
data = outlier_t(EP_X(downTrials(11:20)));
EP_X_c(downTrials(11:20)) = data;
clear data;
EP_X_c(upTrials(21)) = NaN; EP_X_c(downTrials(21)) = NaN; % Toss out catch trials
% data = outlier_t(EP_X(upTrials(14:23))); % Outlier for first 20 exposure
% EP_X_c(upTrials(14:23)) = data;
% data = outlier_t(EP_X(downTrials(14:23)));
% EP_X_c(downTrials(14:23)) = data;
% clear data;
EP_X_c(upTrials(22:31)) = EP_X(upTrials(22:31));
EP_X_c(downTrials(22:31)) = EP_X(downTrials(22:31));
data = outlier_t(EP_X(upTrials(32:91))); % Outlier for last 100 exposure
EP_X_c(upTrials(32:91)) = data;
data = outlier_t(EP_X(downTrials(32:91)));
EP_X_c(downTrials(32:91)) = data;
clear data;
data = outlier_t(EP_X(upTrials(92:96))); % Outlier for first 10 post-exp
EP_X_c(upTrials(92:96)) = data;
data = outlier_t(EP_X(downTrials(92:96)));
EP_X_c(downTrials(92:96)) = data;
clear data;
data = outlier_t(EP_X(upTrials(97:111))); % Outlier for last 10 post-exp
EP_X_c(upTrials(97:111)) = data;
data = outlier_t(EP_X(downTrials(97:111)));
EP_X_c(downTrials(97:111)) = data;
clear data;
% transpose and calculate standardized variable
EP_X_c = EP_X_c';
bvup_mean = nanmean(EP_X_c(upTrials(1:10)));
bvup_std = nanstd(EP_X_c(upTrials(1:10)));
EP_X_up_st = (EP_X_c(upTrials) - bvup_mean)/bvup_std;
bvdown_mean = nanmean(EP_X_c(downTrials(1:10)));
bvdown_std = nanstd(EP_X_c(downTrials(1:10)));
EP_X_down_st = (EP_X_c(downTrials) - bvdown_mean)/bvdown_std;
clear bvup_mean; clear bvup_std; clear bvdown_mean; clear bvdown_std;
%% Plotting Code for EP_X
figure
set(gcf,'Color','w','Position',[560 528 600 420])
hold on;
subplot('Position',[0.06 0.2 0.1 0.6]); hold on;
plot(upTrials(1:10),EP_X(upTrials(1:10)),'bo');
hold on
plot(upTrials(1:10),EP_X_c(upTrials(1:10)),'bx');
hold on
plot(downTrials(1:10),EP_X(downTrials(1:10)),'ro');
hold on
plot(downTrials(1:10),EP_X_c(downTrials(1:10)),'rx');
axis([0 20 -20 20]); set(gca,'LineWidth',2,'XTick',[1 10 20],'YTick',-20:4:20,'YTickLabel',-20:4:20,'FontName','Arial','FontSize',10); ylabel('EP_X [cm]'); title('vis-pre','fontsize',11);
hold on
line([0 20],[0 0],'LineStyle','--','Color',[.5 .5 .5])
hold on
subplot('Position',[0.19 0.2 0.1 0.6]); hold on;
plot(upTrials(11:20)-kbTrials(1)+1,EP_X(upTrials(11:20)),'bo');
hold on
plot(upTrials(11:20)-kbTrials(1)+1,EP_X_c(upTrials(11:20)),'bx');
hold on
plot(downTrials(11:20)-kbTrials(1)+1,EP_X(downTrials(11:20)),'ro');
hold on
plot(downTrials(11:20)-kbTrials(1)+1,EP_X_c(downTrials(11:20)),'rx');
axis([0 20 -20 20]); set(gca,'LineWidth',2,'XTick',[1 10 20],'YTick',[],'YTickLabel',[],'FontName','Arial','FontSize',10); title('kin-pre','fontsize',11);
hold on
line([0 20],[0 0],'LineStyle','--','Color',[.5 .5 .5])
hold on
subplot('Position',[0.32 0.2 0.4 0.6]); hold on;
plot(upTrials(22:91)-exTrials(1)+1,EP_X(upTrials(22:91)),'bo');
hold on
plot(upTrials(22:91)-exTrials(1)+1,EP_X_c(upTrials(22:91)),'bx');
hold on
plot(downTrials(22:91)-exTrials(1)+1,EP_X(downTrials(22:91)),'ro');
hold on
plot(downTrials(22:91)-exTrials(1)+1,EP_X_c(downTrials(22:91)),'rx');
axis([0 140 -20 20]); set(gca,'LineWidth',2,'XTick',[1 20 70 120 140],'YTick',[],'YTickLabel',[],'FontName','Arial','FontSize',10); title(['exposure'], 'fontsize',11); xlabel('Trials','fontsize',11);
hold on
line([0 140],[0 0],'LineStyle','--','Color',[.5 .5 .5])
hold on
subplot('Position',[0.75 0.2 0.24 0.6]); hold on;
plot(upTrials(92:111)-peTrials(1)+1,EP_X(upTrials(92:111)),'bo');
hold on
plot(upTrials(92:111)-peTrials(1)+1,EP_X_c(upTrials(92:111)),'bx');
hold on
plot(downTrials(92:111)-peTrials(1)+1,EP_X(downTrials(92:111)),'ro');
hold on
plot(downTrials(92:111)-peTrials(1)+1,EP_X_c(downTrials(92:111)),'rx');
axis([0 40 -20 20]); set(gca,'LineWidth',2,'XTick',[1 20 40],'YTick',[],'YTickLabel',[],'FontName','Arial','FontSize',10); title(['post-exposure'], 'fontsize',11); xlabel('Trials','fontsize',11);
hold on
line([0 40],[0 0],'LineStyle','--','Color',[.5 .5 .5])
title('EP_X')
%% EP_Y outlier analysis
data = outlier_t(EP_Y(upTrials(1:10))); % Outlier for visual baseline
EP_Y_c(upTrials(1:10)) = data;
data = outlier_t(EP_Y(downTrials(1:10)));
EP_Y_c(downTrials(1:10)) = data;
clear data;
data = outlier_t(EP_Y(upTrials(11:20))); % Outlier for kin baseline
EP_Y_c(upTrials(11:20)) = data;
data = outlier_t(EP_Y(downTrials(11:20)));
EP_Y_c(downTrials(11:20)) = data;
clear data;
EP_Y_c(upTrials(21)) = NaN; EP_Y_c(downTrials(21)) = NaN; % Toss out catch trials
% data = outlier_t(EP_Y(upTrials(14:23))); % Outlier for first 20 exposure
% EP_Y_c(upTrials(14:23)) = data;
% data = outlier_t(EP_Y(downTrials(14:23)));
% EP_Y_c(downTrials(14:23)) = data;
% clear data;
EP_Y_c(upTrials(22:31)) = EP_Y(upTrials(22:31));
EP_Y_c(downTrials(22:31)) = EP_Y(downTrials(22:31));
data = outlier_t(EP_Y(upTrials(32:91))); % Outlier for last 100 exposure
EP_Y_c(upTrials(32:91)) = data;
data = outlier_t(EP_Y(downTrials(32:91)));
EP_Y_c(downTrials(32:91)) = data;
clear data;
data = outlier_t(EP_Y(upTrials(92:96))); % Outlier for first 10 post-exp
EP_Y_c(upTrials(92:96)) = data;
data = outlier_t(EP_Y(downTrials(92:96)));
EP_Y_c(downTrials(92:96)) = data;
clear data;
data = outlier_t(EP_Y(upTrials(97:111))); % Outlier for last 10 post-exp
EP_Y_c(upTrials(97:111)) = data;
data = outlier_t(EP_Y(downTrials(97:111)));
EP_Y_c(downTrials(97:111)) = data;
clear data;
% transpose and calculate standardized variable
EP_Y_c = EP_Y_c';
bvup_mean = nanmean(EP_Y_c(upTrials(1:10)));
bvup_std = nanstd(EP_Y_c(upTrials(1:10)));
EP_Y_up_st = (EP_Y_c(upTrials) - bvup_mean)/bvup_std;
bvdown_mean = nanmean(EP_Y_c(downTrials(1:10)));
bvdown_std = nanstd(EP_Y_c(downTrials(1:10)));
EP_Y_down_st = (EP_Y_c(downTrials) - bvdown_mean)/bvdown_std;
clear bvup_mean; clear bvup_std; clear bvdown_mean; clear bvdown_std;
%% Plotting Code for EP_Y
figure
set(gcf,'Color','w','Position',[560 528 600 420])
hold on;
subplot('Position',[0.06 0.2 0.1 0.6]); hold on;
plot(upTrials(1:10),EP_Y(upTrials(1:10)),'bo');
hold on
plot(upTrials(1:10),EP_Y_c(upTrials(1:10)),'bx');
hold on
plot(downTrials(1:10),EP_Y(downTrials(1:10)),'ro');
hold on
plot(downTrials(1:10),EP_Y_c(downTrials(1:10)),'rx');
axis([0 20 -20 20]); set(gca,'LineWidth',2,'XTick',[1 10 20],'YTick',-20:4:20,'YTickLabel',-20:4:20,'FontName','Arial','FontSize',10); ylabel('EP_Y [cm]'); title('vis-pre','fontsize',11);
hold on
line([0 20],[0 0],'LineStyle','--','Color',[.5 .5 .5])
hold on
subplot('Position',[0.19 0.2 0.1 0.6]); hold on;
plot(upTrials(11:20)-kbTrials(1)+1,EP_Y(upTrials(11:20)),'bo');
hold on
plot(upTrials(11:20)-kbTrials(1)+1,EP_Y_c(upTrials(11:20)),'bx');
hold on
plot(downTrials(11:20)-kbTrials(1)+1,EP_Y(downTrials(11:20)),'ro');
hold on
plot(downTrials(11:20)-kbTrials(1)+1,EP_Y_c(downTrials(11:20)),'rx');
axis([0 20 -20 20]); set(gca,'LineWidth',2,'XTick',[1 10 20],'YTick',[],'YTickLabel',[],'FontName','Arial','FontSize',10); title('kin-pre','fontsize',11);
hold on
line([0 20],[0 0],'LineStyle','--','Color',[.5 .5 .5])
hold on
subplot('Position',[0.32 0.2 0.4 0.6]); hold on;
plot(upTrials(22:91)-exTrials(1)+1,EP_Y(upTrials(22:91)),'bo');
hold on
plot(upTrials(22:91)-exTrials(1)+1,EP_Y_c(upTrials(22:91)),'bx');
hold on
plot(downTrials(22:91)-exTrials(1)+1,EP_Y(downTrials(22:91)),'ro');