Skip to content

Instantly share code, notes, and snippets.

View mattgaidica's full-sized avatar
💭
Spending most my time at https://github.com/Neurotech-Hub

Matt Gaidica, Ph.D. mattgaidica

💭
Spending most my time at https://github.com/Neurotech-Hub
View GitHub Profile
@mattgaidica
mattgaidica / sz.m
Created December 28, 2018 16:09
output a variable's size using >> sz
% output a variable's size using >> sz
w = whos;
findvar = clipboard('paste');
ii = strcmp({w.name},findvar);
if any(ii)
w(ii).size
else
disp(sprintf("\nNo variable '%s'\n",findvar));
end
clearvars('-except',w(:).name);
@mattgaidica
mattgaidica / workon.m
Last active January 24, 2019 15:36
List or edit recently modified files
function workon(openArr)
% (list) >> workon
% (open) >> workon(1)
% (open) >> workon([2,3,6,14])
% (open) >> workon(1:7)
limitTo = 15; % # of files
listing = dir('**/*.m');
[~,idx] = sort([listing.datenum],'descend');
testVals = 0:1000000:100000000; % 0 to 100 million, step 1 million
nTests = numel(testVals);
runTest = true;
if runTest
tVals_uninit = [];
for iTest = 1:nTests
disp(iTest);
a = [];
tic;
filename = 'ExampleData.csv';
data = csvread(filename,1);
t = data(:,1);
velocityThresh = 10; % eye-balled this
minpeakdist = 100; % in samples
extractRange = -20:100; % padding not handled
t_compiled = t(1:numel(extractRange));
eyeHorizontal = rad2deg(data(:,2));
eyeVelocity = filterVelocity(diff(eyeHorizontal));
@mattgaidica
mattgaidica / groundTruthLFP.m
Last active February 8, 2019 15:02
Generates a ground truth local field potential
function [lfp,t] = groundTruthLFP(timePeriod,Fs,oscillationFreq,oscillationOnOff,oscillationAmp)
% timePeriod: LFP length in seconds
% Fs: sampling rate in Hz
% oscillationFreq: n x 1
% oscillationOnset: n x 2
% oscillationAmp: n x 1
% check for errors in inputs
if any(oscillationFreq > Fs / 2)
error('Insufficient resolution for high frequency oscillations');
timePeriod = 10;
Fs = 1000;
oscillationFreq = [4;10;30;75];
oscillationOnOff = [0,10;1,2;0,5;6,9];
oscillationAmp = [1;1;3;2];
[lfp,t] = groundTruthLFP(timePeriod,Fs,oscillationFreq,oscillationOnOff,oscillationAmp);
timePeriod = 3;
Fs = 1000;
oscillationFreq = [4;6;8];
oscillationOnOff = [0 2;1 3;1.5 2.5];
[lfp,t] = groundTruthLFP(timePeriod,Fs,oscillationFreq,oscillationOnOff);
@mattgaidica
mattgaidica / despike.m
Created October 2, 2019 21:31
Despikes neural data using linear interpolation
function dataDespiked = despike(data,Fs,spikeTs,spikeWidth)
% data: raw neural recording data
% Fs: sampling frequency
% spikeTs: spike timestamps in seconds
% spikeWith: width of average spike in ms to replace
% display a plot of the replaced spikes at the end
doDebug = true;
% convert spikeTs (in s) to samples
@mattgaidica
mattgaidica / run_firstLastDate.m
Created February 19, 2020 16:29
Complete_Pero_Master_1.29.20
csvPath = "/Users/matt/Documents/MATLAB/Misc/Complete_Pero_Master_1.29.20_dateFMT.csv";
T = readtable(csvPath);
% augment table
firstCaught = cell(size(T,1),1);
lastCaught = firstCaught;
% new table
new_firstCaught = {};
new_lastCaught = {};
new_mouseID = {};
@mattgaidica
mattgaidica / paletteMaker.m
Created March 11, 2020 14:11
Creates a color palette (i.e. colormap) by selecting points on an image
function mypal = paletteMaker(paletteImPath)
% input: image path for your palette
% output: color palette as a colormap
im = imresize(imread(paletteImPath),0.5);
figure;
imshow(im);
[xs,ys,mypal] = impixel();
for iColor = 1:size(mypal,1)