add trajectory plot
Christoph Budziszewski

Christoph Budziszewski commited on 2009-10-14 14:45:40
Zeige 2 geänderte Dateien mit 138 Einfügungen und 6 Löschungen.


git-svn-id: https://svn.discofish.de/MATLAB/spmtoolbox/SVMCrossVal@209 83ab2cfd-5345-466c-8aeb-2b2739fb922d
... ...
@@ -12,6 +12,7 @@ frameEnd          = frameshift.frameShiftEnd;
12 12
 nClasses          = numel(header.classDef.labelCells);
13 13
 decodePerformance = decode.decodePerformance;
14 14
 psth              = decode.rawTimeCourse;
15
+ert               = psth; % Rename to EventRelatedTimeline
15 16
 SubjectID         = subjectData;
16 17
 
17 18
 nSubjects         = size(SubjectID,2);
... ...
@@ -29,7 +32,13 @@ nTrials           = getNTrials(psth);
29 32
 plottime= tic;
30 33
     switch type
31 34
         case 'psth'
32
-            plotPSTH(psth,psthStart,psthEnd);  
35
+            plotPSTH(ert,psthStart,psthEnd);  
36
+            
37
+        case 'trajectory'
38
+            plotTrajectory(ert,psthStart,psthEnd);
39
+
40
+        case 'trajectory3'
41
+            plotTrajectory3(ert);
33 42
 
34 43
         case 'simple'
35 44
             plotDecodePerformanceWithSE(frameStart,frameEnd,decodePerformance)
... ...
@@ -129,6 +138,115 @@ PSTH_AXIS_MAX = 2;
129 138
 end
130 139
 
131 140
 
141
+function plotTrajectory(psth,psthStart,psthEnd)
142
+% ERTA_AXIS_MAX = 2;
143
+% ERTA_AXIS_MIN = 2;
144
+% ERTB_AXIS_MAX = 2;
145
+% ERTB_AXIS_MIN = 2;
146
+
147
+    if (mod(size(psth,2),2)==0) %% TODO insufficient test!!!
148
+    hold on;
149
+%     grid on;
150
+    for voxel = 1:2:size(psth,2)
151
+        for label = 1:size(psth{voxel},2)
152
+            ertDataA = [];
153
+            for timepoint = 1:size(psth{voxel}{label},2)
154
+                ertDataA = nanmean(psth{voxel}{label}); % mean ueber die trials
155
+            end
156
+%               ERTA_AXIS_MAX = max(ERTA_AXIS_MAX,nanmax(ertDataA));
157
+%               ERTA_AXIS_MIN = min(ERTA_AXIS_MIN,nanmin(ertDataA));
158
+
159
+            voxel2 = voxel+1;
160
+            ertDataB = [];
161
+            for timepoint = 1:size(psth{voxel2}{label},2)
162
+                ertDataB = nanmean(psth{voxel2}{label}); % mean ueber die trials
163
+            end
164
+%               ERTB_AXIS_MAX = max(ERTB_AXIS_MAX,nanmax(ertDataB));
165
+%               ERTB_AXIS_MIN = min(ERTB_AXIS_MIN,nanmin(ertDataB));
166
+              
167
+            plot3(psthStart:psthEnd,ertDataA,ertDataB,['.', colorChooser(label),'-']);
168
+        end
169
+    end
170
+%     axis([psthStart psthEnd ERTA_AXIS_MIN ERTA_AXIS_MAX ERTB_AXIS_MIN ERTB_AXIS_MAX])
171
+    axis tight;
172
+    view(90,0);
173
+    xlabel('time [sec]');
174
+    ylabel('fMRI-signal change [%] A');
175
+    zlabel('fMRI-signal change [%] B');
176
+    
177
+    hold off
178
+    
179
+    
180
+    else 
181
+        display('unsuitable # of voxel/roi!');
182
+    end
183
+
184
+end
185
+
186
+function plotTrajectory3(ert)
187
+    
188
+    if (mod(size(ert,2),3)~=0)
189
+        display('unsuitable # of voxel/roi!');
190
+        return
191
+    end
192
+        
193
+    nSubjects = size(ert,2)/3;
194
+    
195
+%     nLabel = size(ert{1},2);  % this is sane, because the program produces only such things.
196
+    subplot(2,1,1);
197
+    hold on;
198
+%     for label = 1:nLabel 
199
+        ertDataA = ertDataMatrix(ert,1,1,nSubjects);
200
+        ertDataB = ertDataMatrix(ert,1,2,nSubjects);
201
+        ertDataC = ertDataMatrix(ert,1,3,nSubjects);
202
+
203
+        plot3(ertDataA,ertDataB,ertDataC,['.', colorChooser(1),'-']);
204
+
205
+        ertDataA2 = ertDataMatrix(ert,2,1,nSubjects);
206
+        ertDataB2 = ertDataMatrix(ert,2,2,nSubjects);
207
+        ertDataC2 = ertDataMatrix(ert,2,3,nSubjects);
208
+
209
+        plot3(ertDataA2,ertDataB2,ertDataC2,['.', colorChooser(2),'-']);
210
+
211
+        %     end
212
+        
213
+        for a = 1:length(ertDataA)
214
+            line([ertDataA(a) ertDataA2(a)],...
215
+                [ertDataB(a) ertDataB2(a)],...
216
+                [ertDataC(a) ertDataC2(a)],...
217
+                'color',[.8/a 0 1-.8/a]);
218
+            
219
+            d(a) = sqrt( (ertDataA(a)-ertDataA2(a))^2 +...
220
+            (ertDataB(a)-ertDataB2(a))^2 + ...
221
+            (ertDataC(a)-ertDataC2(a))^2);
222
+        end
223
+
224
+    axis tight;
225
+%     view(90,0);
226
+    xlabel('fMRI-signal change [%] A');
227
+    ylabel('fMRI-signal change [%] B');
228
+    zlabel('fMRI-signal change [%] C');
229
+    
230
+    hold off
231
+
232
+    subplot(2,1,2);
233
+        
234
+    plot(d);
235
+    
236
+end
237
+
238
+function ertDataMatrix = ertDataMatrix(ert,label,roiID,nSubjects)
239
+    ertDataMatrix = [];
240
+    for subject = 1:nSubjects
241
+        voxel = roiID*subject;
242
+        for timepoint = 1:size(ert{voxel}{label},2)
243
+            ertDataMatrix = [ertDataMatrix ; nanmean(ert{voxel}{label})]; % mean ueber die trials
244
+        end
245
+    end
246
+    ertDataMatrix = nanmean(ertDataMatrix,1);
247
+end
248
+
249
+
132 250
 function color = colorChooser(n)
133 251
     switch (mod(n,8))
134 252
     case 0
... ...
@@ -436,15 +436,21 @@ end
436 436
 
437 437
 function model = createVisualStepPanel(model,parent)
438 438
 
439
-    grid_h = 0.25;
439
+    grid_h = 0.125;
440 440
     grid_w = 0.5;
441
-    plot_grid = cell([3 3]);
441
+    plot_grid = cell([3 8]);
442 442
     plot_grid{1,1} = [0.0 0.63 grid_w grid_h];
443 443
     plot_grid{1,2} = [0.0 0.33 grid_w grid_h];
444 444
     plot_grid{1,3} = [0.0 0.03 grid_w grid_h];
445
-    plot_grid{2,1} = [0.25 0.63 grid_w grid_h];
446
-    plot_grid{2,2} = [0.25 0.33 grid_w grid_h];
447
-    plot_grid{2,3} = [0.25 0.03 grid_w grid_h];
445
+    plot_grid{2,1} = [0.25 (1-1*grid_h) grid_w grid_h];
446
+    plot_grid{2,2} = [0.25 (1-2*grid_h) grid_w grid_h];
447
+    plot_grid{2,3} = [0.25 (1-3*grid_h) grid_w grid_h];
448
+    plot_grid{2,4} = [0.25 (1-4*grid_h) grid_w grid_h];
449
+    plot_grid{2,5} = [0.25 (1-5*grid_h) grid_w grid_h];
450
+    plot_grid{2,6} = [0.25 (1-6*grid_h) grid_w grid_h];
451
+    plot_grid{2,7} = [0.25 (1-7*grid_h) grid_w grid_h];
452
+    plot_grid{2,8} = [0.25 (1-8*grid_h) grid_w grid_h];
453
+
448 454
     
449 455
     pButtonPane = uipanel(parent,'Units','normalized','Position',[0 0.5 1 0.5]);
450 456
 %     set(pButtonPane,'Title','Plot');
... ...
@@ -468,7 +474,17 @@ function model = createVisualStepPanel(model,parent)
468 474
     set(btnPlot02,'Callback',{@cbPlot,model,'x-subject-val'});
469 475
     set(btnPlot02,'Enable','on');
470 476
 
477
+    btnPlotT1 = uicontrol(pButtonPane,'String','Plot Trajectory (t vs A vs B)',...
478
+        'Units','normalized',...
479
+        'Position',cell2mat(plot_grid(2,4)));
480
+    set(btnPlotT1,'Callback',{@cbPlot,model,'trajectory'});
481
+    set(btnPlotT1,'Enable','on');
471 482
 
483
+    btnPlotT2 = uicontrol(pButtonPane,'String','Plot Trajectory (A vs B vs C)',...
484
+        'Units','normalized',...
485
+        'Position',cell2mat(plot_grid(2,5)));
486
+    set(btnPlotT2,'Callback',{@cbPlot,model,'trajectory3'});
487
+    set(btnPlotT2,'Enable','on');
472 488
 end
473 489
 
474 490
 %%%%% ui callbacks
475 491