-
Notifications
You must be signed in to change notification settings - Fork 1
/
reachExampleFig.m
161 lines (132 loc) · 6.87 KB
/
reachExampleFig.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
% reachExampleFig.m
% Figure 1D
% Plot experimental setup with example target-distractor and
% target-obstacle reach trajectories
clear all; close all; clc;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% Load in a subject's data
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Specify directory with scripts and data files for this project
homeDir = pwd; % Home
addpath(homeDir)
sub = 1; % Choose a subject
dataDir = [homeDir '\Data']; % Folder with all participant data .mat files
cd(dataDir);
subFolders = dir('OR*'); % Identify in Study 2 Files
load(subFolders(sub).name); % Load in data_struct for this subject
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% Plot target-distractor trial in 3D
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Find target-distractor trials that start on the left side
targDistractor = find(data_struct.matData.startSide == 1 & ...
(data_struct.matData.startSide == data_struct.matData.reachSide));
trial = targDistractor(6); % Choose a target-distractor trial to plot
pods = figure; hold on; axis equal; view(-20,25);
% Plot example reach
plot3(data_struct.newFda.x(trial,:)-.3,data_struct.newFda.y(trial,:),data_struct.newFda.z(trial,:)*-1,'linew',2)
% Left iPod
patch([-0.14 -0.06 -0.06 -0.14]',[0.03 0.03 0.03 0.03]',[0 0 0.14 0.14]',[0.94 0.94 0.94]); % back
patch([-0.14 -0.06 -0.06 -0.14]',[0 0 0 0]',[0 0 0.14 0.14]',[0.94 0.94 0.94]); % front
patch([-0.14 -0.14 -0.14 -0.14]',[0 0.03 0.03 0]',[0 0 0.14 0.14]',[0.94 0.94 0.94]); % left
patch([-0.06 -0.06 -0.06 -0.06]',[0 0.03 0.03 0]',[0 0 0.14 0.14]',[0.94 0.94 0.94]); % right
patch([-0.14 -0.06 -0.06 -0.14]',[0 0 0.03 0.03]',[0.14 0.14 0.14 0.14]',[0.94 0.94 0.94]); % top
% Right iPod
patch([0.14 0.06 0.06 0.14]',[0.03 0.03 0.03 0.03]',[0 0 0.14 0.14]',[0.94 0.94 0.94]); % back
patch([0.14 0.06 0.06 0.14]',[0 0 0 0]',[0 0 0.14 0.14]',[0.94 0.94 0.94]); % front
patch([0.14 0.14 0.14 0.14]',[0 0.03 0.03 0]',[0 0 0.14 0.14]',[0.94 0.94 0.94]); % left
patch([0.06 0.06 0.06 0.06]',[0 0.03 0.03 0]',[0 0 0.14 0.14]',[0.94 0.94 0.94]); % right
patch([0.14 0.06 0.06 0.14]',[0 0 0.03 0.03]',[0.14 0.14 0.14 0.14]',[0.94 0.94 0.94]); % top
% Table
patch([-0.425 0.425 0.425 -0.425]',[-0.3 -0.3 0.3 0.3]',[0 0 0 0]',[0.94 0.94 0.94]); % top
% Start circle
C = [0,-0.2,0.003]; R = .005; % Center and radius of circle
teta=0:0.01:2*pi; x=C(1)+R*cos(teta); y=C(2)+R*sin(teta); z=C(3)+zeros(size(x));
patch(x,y,z,'k');
C = [0,-0.2,0.003]; R = .003; % Center and radius of circle
teta=0:0.01:2*pi; x=C(1)+R*cos(teta); y=C(2)+R*sin(teta); z=C(3)+zeros(size(x));
patch(x,y,z,'w');
% Fixation
patch([-0.002 0.002 0.002 -0.002]',[0.09 0.09 0.11 0.11]',[0.003 0.003 0.003 0.003]',[0 0 0],'EdgeColor','None'); % back
patch([-0.01 0.01 0.01 -0.01]',[0.098 0.098 0.102 0.102]',[0.003 0.003 0.003 0.003]',[0 0 0],'EdgeColor','None'); % back
% Left circle
C = [-0.3,0,0.003]; R = .005; % Center and radius of circle
teta=0:0.01:2*pi; x=C(1)+R*cos(teta); y=C(2)+R*sin(teta); z=C(3)+zeros(size(x));
patch(x,y,z,'k');
C = [-0.3,0,0.003]; R = .003; % Center and radius of circle
teta=0:0.01:2*pi; x=C(1)+R*cos(teta); y=C(2)+R*sin(teta); z=C(3)+zeros(size(x));
patch(x,y,z,'w');
% Right circle
C = [0.3,0,0.003]; R = .005; % Center and radius of circle
teta=0:0.01:2*pi; x=C(1)+R*cos(teta); y=C(2)+R*sin(teta); z=C(3)+zeros(size(x));
patch(x,y,z,'k');
C = [0.3,0,0.003]; R = .003; % Center and radius of circle
teta=0:0.01:2*pi; x=C(1)+R*cos(teta); y=C(2)+R*sin(teta); z=C(3)+zeros(size(x));
patch(x,y,z,'w');
% Plotting options
xlim([-.42 .42]); ylim([-.25 .25]); zlim([-.01 .3]);
axis equal;
xlabel('x (cm)');
ylabel('y (cm)');
zlabel('z (cm)');
set(gca,'FontSize',12);
set(gcf,'color','w');
cd(homeDir);
saveas(gcf,'targetDistractorExample','svg'); % Save figure in .svg file format
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% Plot target-obstacle trial in 3D
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Find target-distractor trials that start on the left side
targDistractor = find(data_struct.matData.startSide == 1 & ...
(data_struct.matData.startSide ~= data_struct.matData.reachSide));
trial = targDistractor(10); % Choose a target-distractor trial to plot
pods = figure; hold on; axis equal; view(-20,25);
% Plot example reach
plot3(data_struct.newFda.x(trial,:)-.3,data_struct.newFda.y(trial,:),data_struct.newFda.z(trial,:)*-1,'linew',2)
% Left iPod
patch([-0.14 -0.06 -0.06 -0.14]',[0.03 0.03 0.03 0.03]',[0 0 0.14 0.14]',[0.94 0.94 0.94]); % back
patch([-0.14 -0.06 -0.06 -0.14]',[0 0 0 0]',[0 0 0.14 0.14]',[0.94 0.94 0.94]); % front
patch([-0.14 -0.14 -0.14 -0.14]',[0 0.03 0.03 0]',[0 0 0.14 0.14]',[0.94 0.94 0.94]); % left
patch([-0.06 -0.06 -0.06 -0.06]',[0 0.03 0.03 0]',[0 0 0.14 0.14]',[0.94 0.94 0.94]); % right
patch([-0.14 -0.06 -0.06 -0.14]',[0 0 0.03 0.03]',[0.14 0.14 0.14 0.14]',[0.94 0.94 0.94]); % top
% Right iPod
patch([0.14 0.06 0.06 0.14]',[0.03 0.03 0.03 0.03]',[0 0 0.14 0.14]',[0.94 0.94 0.94]); % back
patch([0.14 0.06 0.06 0.14]',[0 0 0 0]',[0 0 0.14 0.14]',[0.94 0.94 0.94]); % front
patch([0.14 0.14 0.14 0.14]',[0 0.03 0.03 0]',[0 0 0.14 0.14]',[0.94 0.94 0.94]); % left
patch([0.06 0.06 0.06 0.06]',[0 0.03 0.03 0]',[0 0 0.14 0.14]',[0.94 0.94 0.94]); % right
patch([0.14 0.06 0.06 0.14]',[0 0 0.03 0.03]',[0.14 0.14 0.14 0.14]',[0.94 0.94 0.94]); % top
% Table
patch([-0.425 0.425 0.425 -0.425]',[-0.3 -0.3 0.3 0.3]',[0 0 0 0]',[0.94 0.94 0.94]); % top
% Start circle
C = [0,-0.2,0.003]; R = .005; % Center and radius of circle
teta=0:0.01:2*pi; x=C(1)+R*cos(teta); y=C(2)+R*sin(teta); z=C(3)+zeros(size(x));
patch(x,y,z,'k');
C = [0,-0.2,0.003]; R = .003; % Center and radius of circle
teta=0:0.01:2*pi; x=C(1)+R*cos(teta); y=C(2)+R*sin(teta); z=C(3)+zeros(size(x));
patch(x,y,z,'w');
% Fixation
patch([-0.002 0.002 0.002 -0.002]',[0.09 0.09 0.11 0.11]',[0.003 0.003 0.003 0.003]',[0 0 0],'EdgeColor','None'); % back
patch([-0.01 0.01 0.01 -0.01]',[0.098 0.098 0.102 0.102]',[0.003 0.003 0.003 0.003]',[0 0 0],'EdgeColor','None'); % back
% Left circle
C = [-0.3,0,0.003]; R = .005; % Center and radius of circle
teta=0:0.01:2*pi; x=C(1)+R*cos(teta); y=C(2)+R*sin(teta); z=C(3)+zeros(size(x));
patch(x,y,z,'k');
C = [-0.3,0,0.003]; R = .003; % Center and radius of circle
teta=0:0.01:2*pi; x=C(1)+R*cos(teta); y=C(2)+R*sin(teta); z=C(3)+zeros(size(x));
patch(x,y,z,'w');
% Right circle
C = [0.3,0,0.003]; R = .005; % Center and radius of circle
teta=0:0.01:2*pi; x=C(1)+R*cos(teta); y=C(2)+R*sin(teta); z=C(3)+zeros(size(x));
patch(x,y,z,'k');
C = [0.3,0,0.003]; R = .003; % Center and radius of circle
teta=0:0.01:2*pi; x=C(1)+R*cos(teta); y=C(2)+R*sin(teta); z=C(3)+zeros(size(x));
patch(x,y,z,'w');
% Plotting options
xlim([-.42 .42]); ylim([-.25 .25]); zlim([-.01 .3]);
axis equal;
xlabel('x (cm)');
ylabel('y (cm)');
zlabel('z (cm)');
set(gca,'FontSize',12);
set(gcf,'color','w');
cd(homeDir);
saveas(gcf,'targetObstacleExample','svg'); % Save figure in .svg file format