ampAtStim_curveset.m 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. function ampAtStim_curveset(files, varargin)
  2. %% Amplitude during a stimulation analysed over the trials
  3. % This function helps to analyse time effects on the amplitude of the
  4. % membrane potential during stimulation. The amplitude values are obtained
  5. % from the 'ampAtStim' function and are plotted with one curve per trial.
  6. % -------------------------------------------------------------------------
  7. % Input [additional arguments are positional,
  8. % ----- optional arguments are name-value pairs]
  9. %
  10. % files: ID of the datafile(s) in the data directory
  11. % type: integer or vector
  12. % Trials: select the trials which should be used. Default: 'all'
  13. % (additional) type: integer or vector
  14. % Filter: select between three filter options:
  15. % (optional) 'hn' applys a hum-noise-remove filter
  16. % 'hnhfn' additonally applys a low pass filter to remove
  17. % high frequency noise
  18. % If not set, it will be set to "no" (default).
  19. % StimCell: set whether to plot the data for a stimulated T-cell ('T')
  20. % (optional): or a stimulated interneuron ('INT'). Default: 'T'
  21. %
  22. % ------
  23. % Output
  24. % ------
  25. % visually output of the plot(s)
  26. % -------------------------------------------------------------------------
  27. % Program by: Bjarne Schultze [last modified 09.03.2022]
  28. % -------------------------------------------------------------------------
  29. %% Preperations
  30. % parse the user input
  31. [file_num, trials, filter_choice, ~, ~, stimCell, ~,~,~] = ...
  32. parse_input_peakfun(files, varargin{:});
  33. % load a file with different colors
  34. load("../AdditionalFiles/colorShades.mat", 'colorShades');
  35. load("../AdditionalFiles/standard_stimulus.mat", "standard_stimulus");
  36. % obtain the amplitudes for the requested files
  37. amps = ampAtStim(file_num, 'Filter', filter_choice);
  38. % obtain the amplitudes of the current pulses
  39. [stim_peaks, ~] = findpeaks(standard_stimulus, 10000);
  40. % find negative stimului (therefor inverting the stimulus data)
  41. [min_stim_peaks, ~] = ...
  42. findpeaks(-standard_stimulus, 10000, 'MinPeakHeight', 0);
  43. % invert the peak values back
  44. min_stim_peaks = -min_stim_peaks;
  45. % concatenating positive and nagative stimlus peak data
  46. all_stim_peaks = [min_stim_peaks; stim_peaks];
  47. % sort the values for the current in ascending order
  48. all_stim_peaks = sort(all_stim_peaks);
  49. %% Plot the results
  50. for file = 1:length(file_num)
  51. trial_num = size(amps{file,1}.AmplitudeT,2);
  52. % select the trials according to the stimulated cell (stimCell)
  53. if isequal(stimCell, "INT")
  54. stimulated = setdiff(1:trial_num, amps{file,1}.stimulatedT, ...
  55. 'stable');
  56. plot_title = sprintf("File: %02.f - Interneuron stimulated", ...
  57. file_num(file));
  58. else
  59. stimulated = amps{file,1}.stimulatedT(:);
  60. plot_title = sprintf("File: %02.f - T-cell stimulated", ...
  61. file_num(file));
  62. end
  63. % if requested, select only certain trials
  64. if ~isequal(trials, 'all')
  65. stimulated = intersect(trials, stimulated);
  66. end
  67. % check if there are trials selected for which the data can be plotted
  68. if ~isempty(stimulated)
  69. % plot the data for the first selected trial
  70. figure('Position',[120,67,1278,694]);
  71. plot(all_stim_peaks, amps{file,1}.AmplitudeT(:,stimulated(1)), ...
  72. '-o', 'Color', colorShades.blue(1,:))
  73. hold on;
  74. plot(all_stim_peaks, amps{file,1}.AmplitudeINT(:,stimulated(1)), ...
  75. '-o', 'Color', colorShades.red(1,:));
  76. title(plot_title);
  77. xlabel("stimulation current [nA]");
  78. ylabel("amplitude of the membrane potential [mV]");
  79. yline(0, 'Color', [0.6 0.6 0.6])
  80. legend("T-cell", "Interneuron", 'Location','best', ...
  81. 'AutoUpdate','off');
  82. % plot the data for all the other trials, each with a brighter
  83. % color shade
  84. for col = 2:length(stimulated)
  85. % if not enough color shades are available, all later trials
  86. % get the birghtest shade
  87. if col > length(colorShades.blue(:,1))
  88. plot_colorT = colorShades.blue(end,:);
  89. plot_colorINT = colorShades.red(end,:);
  90. else
  91. plot_colorT = colorShades.blue(col,:);
  92. plot_colorINT = colorShades.red(col,:);
  93. end
  94. plot(all_stim_peaks, ...
  95. amps{file,1}.AmplitudeT(:,stimulated(col)), '-o', ...
  96. 'Color', plot_colorT)
  97. plot(all_stim_peaks, ...
  98. amps{file,1}.AmplitudeINT(:,stimulated(col)), '-o', ...
  99. 'Color', plot_colorINT);
  100. end
  101. hold off;
  102. else
  103. % display an error message when there was no trial to plot
  104. fprintf("\nBad trial selection for file %g. No plot created!\n", ...
  105. file_num(file));
  106. end
  107. end
  108. % end of function definition
  109. end