Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

Demo_plot_trial.m 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. % Demo for plotting filtered and unfiltered fixation data
  2. infile='EggertStraube_FixationDriftData.mat';
  3. load(infile,'results');
  4. %% plot the trial shown in the Supporting Information S2 text Fig. A
  5. plot_eyeposition(results);
  6. %% plot all trials of a given task, block, and subject
  7. SID=50;
  8. task_i=1;
  9. block_i=1;
  10. % get the number of trials for this task, block, subject
  11. SIDall=[results(task_i,block_i,:).SubjectIdentifier];
  12. subj_i=find(SIDall==SID,1,'first');
  13. if isempty(subj_i)
  14. error('SID=%d not found.');
  15. end
  16. NValidTrials=length(results(task_i,block_i,subj_i).VersVerg_deg);
  17. for k=1:NValidTrials
  18. figure(k);
  19. plot_eyeposition(results,task_i,block_i,k,SID,k);
  20. end
  21. function plot_eyeposition(results,task_i,block_i,trial_number,SID,fignr)
  22. % plots left and right eye position during valid fixation intervals
  23. %
  24. % Arguments:
  25. % results : structured array stored in EggertStraube_FixationDriftData.mat
  26. % load data before calling : load('EggertStraube_FixationDriftData','results')
  27. % task_i : scalar integer specifying the task type: 1:stereo task, 2: acuity task (default: 1)
  28. % block_i : scalar integer specifying the measurement block: % 1: block A; 2: block B (default: 1)
  29. % trial_number: scalar integer specifying the trial number (default: 6)
  30. % SID : integer vector containig the subject identifiers for which the plot is generated
  31. % SID=[] data of all subjects are be plotted (default: 50)
  32. % fignr : integer specifying the figure number: 0: plot in current figure; >0: plot in this figure(fignr)
  33. %
  34. % calling plot_eyeposition(results) creates the plot shown in Supporting Information S2 text (Fig. A)
  35. if nargin<2 || isempty(task_i)
  36. task_i=1; % 1:stereo, 2: acuity
  37. end
  38. if nargin<3 || isempty(block_i)
  39. block_i=1; % 1: block A; 2: block B
  40. end
  41. if nargin<4 || isempty(trial_number)
  42. trial_number=6; % trial number
  43. end
  44. if nargin<5 || isempty(SID)
  45. SID=50; % subject identifier
  46. end
  47. if nargin<5 || isempty(fignr)
  48. fignr=1; % figure number
  49. end
  50. dim=size(results); % [NuberofTasks, NumberOfBlocks, NumberOfSubjects]
  51. SIDall=[results(1,1,:).SubjectIdentifier];
  52. if ~isempty(SID)
  53. % find the subject index from the subject identifier
  54. subj_i=NaN(size(SID));
  55. for j=1:numel(SID)
  56. ind=find(SIDall==SID(j),1,'first');
  57. if ~isempty(ind)
  58. subj_i(j)=ind;
  59. else
  60. fprintf('SID=%d not found.\n',SID(j));
  61. end
  62. end
  63. subj_i=subj_i(~isnan(subj_i));
  64. SIDall=SIDall(subj_i);
  65. results=results(:,:,subj_i);
  66. end
  67. for subj_i=1:length(SIDall)
  68. NValidTrials=length(results(task_i,block_i,subj_i).VersVerg_deg);
  69. fprintf('number of valid trials: %d\n',NValidTrials);
  70. SamplingRate_Hz=results(task_i,block_i,subj_i).SamplingRate_Hz;
  71. if trial_number>NValidTrials
  72. fprintf('SID=%3d: specified trial number %d replaced by maximum trial number %d:\n',SIDall(subj_i),trial_number,NValidTrials);
  73. vtrialn=NValidTrials;
  74. else
  75. vtrialn=trial_number;
  76. end
  77. VersVerg=results(task_i,block_i,subj_i).VersVerg_deg{vtrialn};
  78. VersVergSlow=results(task_i,block_i,subj_i).VersVergSlow_deg{vtrialn};
  79. Segmentation=results(task_i,block_i,subj_i).Segmentation{vtrialn};
  80. PupilDiameter_mm=results(task_i,block_i,subj_i).PupilDiameter_mm_trace{vtrialn};
  81. SegmentClass=zeros(size(VersVergSlow,1),1);
  82. for fast_class=1:2
  83. sind=find([Segmentation(:).class]==fast_class);
  84. for sacc_i=1:length(sind)
  85. fast_i=floor((Segmentation(sind(sacc_i)).t_start_s+[0,Segmentation(sind(sacc_i)).dur_s])*SamplingRate_Hz)+1;
  86. fast_i=fast_i+[-1,1]*floor(0.001*SamplingRate_Hz);
  87. fast_i(2)=min(fast_i(2),length(SegmentClass));
  88. fast_i(1)=max(1,fast_i(1));
  89. SegmentClass(fast_i(1):fast_i(2))=fast_class;
  90. end
  91. end
  92. Elraw=VersVerg(:,1)+VersVerg(:,2)/2; % raw version and vergence in left eye centred coordinates (deg)
  93. Erraw=VersVerg(:,1)-VersVerg(:,2)/2; % raw version and vergence in right eye centred coordinates (deg)
  94. El=VersVergSlow(:,1)+VersVergSlow(:,2)/2; % cleaned left eye centred coordinates
  95. Er=VersVergSlow(:,1)-VersVergSlow(:,2)/2; % cleaned right eye centred coordinates
  96. t=(0:length(El)-1)'/SamplingRate_Hz;
  97. axh=zeros(3,1);
  98. ph=zeros(2,1);
  99. if fignr>0
  100. figure(fignr);
  101. end
  102. clf
  103. set(gcf,'Position',[53 64 580 794]);
  104. axh(1)=subplot(3,1,1);
  105. hold on
  106. set(gca,'Fontsize',12,'Linewidth',1.5);
  107. title(sprintf('SID=%d: trial #= %d',SIDall(subj_i),vtrialn));
  108. tmp=Elraw;
  109. tmp(SegmentClass==1)=NaN;
  110. ph(1)=plot(t,tmp,'-m','Linewidth',1.5);
  111. tmp=Elraw;
  112. tmp(SegmentClass==0)=NaN;
  113. plot(t,tmp,'--m','Linewidth',1.5);
  114. tmp=El;
  115. tmp(SegmentClass==1)=NaN;
  116. ylims=[1,2]+nanmean(tmp)-1.5;
  117. ph(2)=plot(t,tmp,'-b','Linewidth',1.5);
  118. tmp=El;
  119. tmp(SegmentClass==0)=NaN;
  120. plot(t,tmp,'--b','Linewidth',1.5);
  121. set(gca,'YLim',ylims);
  122. set(get(gca,'YLabel'),'string','left eye position (deg)');
  123. axh(1)=subplot(3,1,2);
  124. hold on
  125. set(gca,'Fontsize',12,'Linewidth',1.5);
  126. tmp=Erraw;
  127. tmp(SegmentClass==1)=NaN;
  128. ph(1)=plot(t,tmp,'-m','Linewidth',1.5);
  129. tmp=Erraw;
  130. tmp(SegmentClass==0)=NaN;
  131. plot(t,tmp,'--m','Linewidth',1.5);
  132. tmp=Er;
  133. tmp(SegmentClass==1)=NaN;
  134. ylims=[-2,-1]+nanmean(tmp)+1.5;
  135. ph(2)=plot(t,tmp,'-b','Linewidth',1.5);
  136. tmp=Er;
  137. tmp(SegmentClass==0)=NaN;
  138. plot(t,tmp,'--b','Linewidth',1.5);
  139. set(gca,'YLim',ylims);
  140. set(get(gca,'YLabel'),'string','right eye position (deg)');
  141. legend(ph,'non-filtered','spline filter');
  142. axh(2)=subplot(3,1,3);
  143. hold on
  144. set(gca,'Fontsize',12,'Linewidth',1.5);
  145. plot(t,PupilDiameter_mm,'-k','Linewidth',1.5);
  146. set(get(gca,'XLabel'),'string','time (s)');
  147. set(get(gca,'YLabel'),'string','pupil diameter (mm)');
  148. figure(gcf);
  149. if subj_i<length(SIDall)
  150. hstr=input('Press ENTER to continue!','s');
  151. end
  152. end
  153. end