123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- function plotData(file,trial,varargin)
- %% Function to plot double recordings and the corresponding stimulus
- % This function takes the 'CleanDatasets' and creates a graphical
- % representation for the recordings plotting the recorded membrane
- % potential over time. The corresponding stimulation protocol is added.
- % Multiple trials can be selected at once as well as multiple files. If
- % requested, the graphics can be saved automatically in the png-format
- % (resolution: 1200) without showing them before.
- %-------------------------------------------------------------------------
- % Input [optional arguments are name value pairs]
- % -----
- % file: ID(s) of the file(s) in the '../CleanDatasets' folder
- % type: integer or vector
- % trial: number(s) of the trials to be plotted, 1 figure window per
- % (additional) trial, type: integer or vector, default: 'all'
- % Filter: select between no filter ('no', default), a hum noise
- % (optional) filter ('hn') or a hum + high frequency filter
- % ('hnhfn')
- % Export: set if the plots should be saved as png files in the folder
- % (optional) '../Images' (1 - yes, 0 - no, default)
- %
- % ------
- % Output
- % ------
- % image files are created in the specified folder
- % OR
- % tiled figures showing the requested data, 1 figure per trial
- %-------------------------------------------------------------------------
- % Program by: Bjarne Schultze [last modified: 28.02.2022]
- %-------------------------------------------------------------------------
- %% Preperations
- % set input parser and validation functions
- p = inputParser;
- valid_in_vector = @(x) isnumeric(x) && isvector(x) && ...
- isequal(length(x),sum(x>0));
- % specify input arguments
- addRequired(p,'file', valid_in_vector)
- addOptional(p,'trial', 'all', valid_in_vector)
- addParameter(p,'Filter','no', @(x) isequal(x,'hn') || ...
- isequal(x,'hnhfn') || isequal(x,'no'))
- addParameter(p,'Export',0, @(x) isequal(x,0) || isequal(x,1))
- % parse user input
- parse(p,file,trial,varargin{:});
- % catch the results
- files = p.Results.file;
- trials = p.Results.trial;
- filter = p.Results.Filter;
- exportFlag = p.Results.Export;
- % set a counter variable to get the number of created images
- counter = uint8(0);
- %% Plotting
- % plotting the stimulus and the recorded data against the time in a
- % tiled figure (not vivsible if png export is requested)
- if exportFlag
- fig = figure('Position', [183 139 1176 623],'visible', 'off');
- end
- % access the data and applying filters if required
- dataIN = extract_data(files, filter);
- for exp = 1:length(files)
- % get the data for the current file
- recData = dataIN{exp,1};
- % determine the number of trials in the file
- if isequal(trials,'all')
- trials = 1:size(recData.recordingT,2);
- end
-
- for trial = trials
- if ~exportFlag
- figure('Position', [183 139 1176 623]);
- end
- % create a plot title which identifies the file and the trial
- plot_title = sprintf("File %02.f - Trial %02.f", ...
- files(exp), trial);
- % set up the layout
- tlayout = tiledlayout(3,1,'Padding','compact');
- title(tlayout, plot_title);
- % plot the data
- nexttile
- plot(recData.timeVector, recData.stimulus) % 1st plot
- xlabel("time [s]",'FontSize', 12);
- ylabel("current [nA]", 'FontSize', 12);
- title("Stimulus");
- nexttile
- plot(recData.timeVector, recData.recordingT(:,trial)); % 2nd plot
- xlabel("time [s]",'FontSize', 12);
- ylabel(["membrane"; "potentail [mV]"],'FontSize', 12);
- title("T cell recording");
- nexttile
- plot(recData.timeVector,recData.recordingINT(:,trial)); % 3rd plot
- xlabel("time [s]",'FontSize', 12);
- ylabel(["membrane"; "potential [mV]"],'FontSize', 12);
- title("Interneuron recording");
-
- % Save the figure to an image file if requested
- if exportFlag
- filename = sprintf("../Images/[%02.f-%02.f]",...
- file(exp), trial);
- print(fig, filename, "-dpng", "-r1200")
- % increase counter for the created images
- counter = counter + 1;
- end
- end
- end
- %% Finishing up
- if exportFlag
- % create an output for the user
- fprintf("\nSuccessfully created %0.f image file(s)! " + ...
- "\nFiles are stored in ../Images\n",counter);
-
- % close the hidden figure used to plot the data for export
- close(fig)
- end
- %end of function definition
- end
|