example_eye_data.m 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. function example_eye_data(filename, n)
  2. %EXAMPLE_EYE_DATA plots eye-movement data.
  3. %
  4. % EXAMPLE_EYE_DATA(filename, n) plots the x-position, y-position, right and
  5. % left pupil size for the first n time steps (1 time step = 1000micro secs)
  6. % for the file specified by filename. It also prints the correlation
  7. % between right and left pupil size across the entire recording.
  8. % This function only works for files that end in "-eye.h5", e.g.
  9. % amm-MSTm-sun-085-01+01-eye.h5
  10. %
  11. % INPUT:
  12. % filename: string; name of a .h5 file from the data folder,
  13. % e.g., 'amm-MSTm-sun-090-01+01-eye.h5'
  14. % n: number of time steps (default is 100)
  15. %
  16. % Benedict Wild (bwild(at)dpz.eu), 2021
  17. if nargin < 2
  18. n = 100;
  19. end
  20. % set parameters for plotting
  21. set(0, 'DefaultLineLineWidth', 2)
  22. set(0,'defaultAxesFontSize', 20)
  23. % read in h5 file
  24. param2read = {'/event_value', '/event_time'};
  25. file_info = h5info(filename, '/event_value'); % Matlab function
  26. events2read = {file_info.Datasets.Name};
  27. [event_value, event_time] = h5_extract(filename, param2read, events2read); % custom function
  28. % savety precaution in case user enters n that is too big
  29. n = min(n, length(event_value.EYE_x_dva));
  30. % Plot
  31. xx = event_time.EYE_x_dva(1:n)-event_time.EYE_x_dva(1);
  32. figure('Color',[1,1,1],'Position',[0, 0, 500, 1200]);
  33. subplot(411);
  34. plot(xx,event_value.EYE_x_dva(1:n));
  35. title('X position');
  36. subplot(412);
  37. plot(xx,event_value.EYE_y_dva(1:n));
  38. title('Y position');
  39. subplot(413);
  40. plot(xx,event_value.EYE_pupilSizeRight_raw(1:n));
  41. title('Pupil Size Right');
  42. subplot(414);
  43. plot(xx,event_value.EYE_pupilSizeLeft_raw(1:n));
  44. title('Pupil Size Left');
  45. xlabel('Time [micro seconds]');
  46. % correlation
  47. fprintf("Correlation between right and left pupil size: %.2f\n", corr(double(event_value.EYE_pupilSizeLeft_raw)',double(event_value.EYE_pupilSizeRight_raw)'));