plotData.m 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. function plotData(file,trial,varargin)
  2. %% Function to plot double recordings and the corresponding stimulus
  3. % This function takes the 'CleanDatasets' and creates a graphical
  4. % representation for the recordings plotting the recorded membrane
  5. % potential over time. The corresponding stimulation protocol is added.
  6. % Multiple trials can be selected at once as well as multiple files. If
  7. % requested, the graphics can be saved automatically in the png-format
  8. % (resolution: 1200) without showing them before.
  9. %-------------------------------------------------------------------------
  10. % Input [optional arguments are name value pairs]
  11. % -----
  12. % file: ID(s) of the file(s) in the '../CleanDatasets' folder
  13. % type: integer or vector
  14. % trial: number(s) of the trials to be plotted, 1 figure window per
  15. % (additional) trial, type: integer or vector, default: 'all'
  16. % Filter: select between no filter ('no', default), a hum noise
  17. % (optional) filter ('hn') or a hum + high frequency filter
  18. % ('hnhfn')
  19. % Export: set if the plots should be saved as png files in the folder
  20. % (optional) '../Images' (1 - yes, 0 - no, default)
  21. %
  22. % ------
  23. % Output
  24. % ------
  25. % image files are created in the specified folder
  26. % OR
  27. % tiled figures showing the requested data, 1 figure per trial
  28. %-------------------------------------------------------------------------
  29. % Program by: Bjarne Schultze [last modified: 28.02.2022]
  30. %-------------------------------------------------------------------------
  31. %% Preperations
  32. % set input parser and validation functions
  33. p = inputParser;
  34. valid_in_vector = @(x) isnumeric(x) && isvector(x) && ...
  35. isequal(length(x),sum(x>0));
  36. % specify input arguments
  37. addRequired(p,'file', valid_in_vector)
  38. addOptional(p,'trial', 'all', valid_in_vector)
  39. addParameter(p,'Filter','no', @(x) isequal(x,'hn') || ...
  40. isequal(x,'hnhfn') || isequal(x,'no'))
  41. addParameter(p,'Export',0, @(x) isequal(x,0) || isequal(x,1))
  42. % parse user input
  43. parse(p,file,trial,varargin{:});
  44. % catch the results
  45. files = p.Results.file;
  46. trials = p.Results.trial;
  47. filter = p.Results.Filter;
  48. exportFlag = p.Results.Export;
  49. % set a counter variable to get the number of created images
  50. counter = uint8(0);
  51. %% Plotting
  52. % plotting the stimulus and the recorded data against the time in a
  53. % tiled figure (not vivsible if png export is requested)
  54. if exportFlag
  55. fig = figure('Position', [183 139 1176 623],'visible', 'off');
  56. end
  57. % access the data and applying filters if required
  58. dataIN = extract_data(files, filter);
  59. for exp = 1:length(files)
  60. % get the data for the current file
  61. recData = dataIN{exp,1};
  62. % determine the number of trials in the file
  63. if isequal(trials,'all')
  64. trials = 1:size(recData.recordingT,2);
  65. end
  66. for trial = trials
  67. if ~exportFlag
  68. figure('Position', [183 139 1176 623]);
  69. end
  70. % create a plot title which identifies the file and the trial
  71. plot_title = sprintf("File %02.f - Trial %02.f", ...
  72. files(exp), trial);
  73. % set up the layout
  74. tlayout = tiledlayout(3,1,'Padding','compact');
  75. title(tlayout, plot_title);
  76. % plot the data
  77. nexttile
  78. plot(recData.timeVector, recData.stimulus) % 1st plot
  79. xlabel("time [s]",'FontSize', 12);
  80. ylabel("current [nA]", 'FontSize', 12);
  81. title("Stimulus");
  82. nexttile
  83. plot(recData.timeVector, recData.recordingT(:,trial)); % 2nd plot
  84. xlabel("time [s]",'FontSize', 12);
  85. ylabel(["membrane"; "potentail [mV]"],'FontSize', 12);
  86. title("T cell recording");
  87. nexttile
  88. plot(recData.timeVector,recData.recordingINT(:,trial)); % 3rd plot
  89. xlabel("time [s]",'FontSize', 12);
  90. ylabel(["membrane"; "potential [mV]"],'FontSize', 12);
  91. title("Interneuron recording");
  92. % Save the figure to an image file if requested
  93. if exportFlag
  94. filename = sprintf("../Images/[%02.f-%02.f]",...
  95. file(exp), trial);
  96. print(fig, filename, "-dpng", "-r1200")
  97. % increase counter for the created images
  98. counter = counter + 1;
  99. end
  100. end
  101. end
  102. %% Finishing up
  103. if exportFlag
  104. % create an output for the user
  105. fprintf("\nSuccessfully created %0.f image file(s)! " + ...
  106. "\nFiles are stored in ../Images\n",counter);
  107. % close the hidden figure used to plot the data for export
  108. close(fig)
  109. end
  110. %end of function definition
  111. end