sha256
stringlengths
64
64
language
stringclasses
27 values
size
int32
1
491k
lines
int32
1
21.8k
content
stringlengths
1
200k
370ff055490fcd8644c2b618af2d3d6ee5cf03aa03b4e464eb3717410e4c94e8
MATLAB
369
16
function combo_mat = all_combos(varargin) num_vars = length(varargin); tmp_str = '['; for i = 1 : num_vars - 1 tmp_str = [tmp_str 'd_' num2str(i) ',']; end tmp_str = [tmp_str 'd_' num2str(num_vars) ']']; eval([tmp_str ' = ndgrid(varargin{:});']); combo_mat = []; for i = 1 : num_vars eval(['combo_mat = [c...
90800e506e3f3edc87cf38815414ede3f0697f8b0b7ba5454b0d5c42ac65c3aa
MATLAB
370
17
clear; close all; clc; T = 200; data1 = randn(600, T); data2 = repmat(randn(1, T), 200, 1); data = [data2; data1; data2]; data = data + 3 * randn(1000, T); option = tNLMGPDF(); option.isPlot = false; option.isVerbose = true; option.memoryLimit = 'auto'; option.numCPU = 'auto'; option.SCBFile = fullfile(pwd, 'SCB.mat'...
56c17e062f0737925720b5c20243d2efb97fe467210ac0ba70022df4d3803a27
MATLAB
371
11
% Clean strings of non-printable characters or characters > 127 % characters > 127 get converted to utf-16 during fwrite, causing data positions % to be shifted. This will prevent that. % authored by David Shattuck % % simple test: % x=char(rand(1,80)*255) % fprintf(1,'%s\n%s\n',x,sanitize_ascii(x)) function str = s...
7d003e7b37a907c2a408f480ace122e8372ffac12ec15fcfce1e3a79696e77c0
MATLAB
374
17
%% % Calls max() on multiple inputs, all of which are arrays. % function [x] = mmax(x, varargin) % Locate arguments i.e. everything not the same size as x function [yes] = testSize(y) yes = ( size(y) == size(x) ); end [arrays, arguments] = separate(@testSize, varargin{:}); for y = arrays ...
c371e8cf7719a75799f3ad71d3f0be9247b65c1c6ec0b1bb2f443b5a02e9870d
MATLAB
374
17
%% % Calls min() on multiple inputs, all of which are arrays. % function [x] = mmin(x, varargin) % Locate arguments i.e. everything not the same size as x function [yes] = testSize(y) yes = ( size(y) == size(x) ); end [arrays, arguments] = separate(@testSize, varargin{:}); for y = arrays ...
ef9c17f2e9577411c6a6960e35e55008b4115ac4c58be0a99b455c53b906aec1
MATLAB
375
12
function out = linear2rgb(inpict) % OUTPICT=LINEAR2RGB(INPICT) % Convert linear RGB to gamma-corrected sRGB % % INPICT is an RGB image of a floating point class. % Output class is inherited from INPICT % % See also: lin2rgb, rgb2linear mk = (inpict <= 0.0031306684425005883); out = 12.92*inpict.*mk + (real(1...
0d044c58f266647c87c964af6b9bc58ec83d3a6d2ee370b1aaad6e58bc657f20
MATLAB
377
19
% Sets both the x- and y-axis labels for the given axes. function xylabel(axs, xText, yText) if nargin < 3 && ischar(axs) yText = xText; xText = axs; axs = curraxes(); end if isequal(axs, inf) axs = allaxes(); end for iAxs = 1:numel(axs) xlabel(axs(iAxs),...
61784909354d442c45ee2d5f4d77ab09e0e5b65fa3d198fa4469bca1f9d7005e
MATLAB
378
17
function w=nt_growmask(w,margin) %ww=nt_growmask(w,margin) - widen mask % % ww: widened mask (samples * 1 or samples * 1 * trials) % % w: mask % margin: samples, number of samples by which to widen the mask % % NoiseTools [m,n,o]=size(w); w=(w~=0); w=nt_unfold(w); w=filter(ones(margin+1,1),1,w)>0; w=flipud(filter(o...
3bb7bcb130425b960f79fa4371fd9c0071e7d86d6a3b65c4773e42406b243fbb
MATLAB
379
22
%% Close all figures and clear all variables/objects/MEX programs. set(findall(0, 'Type', 'figure'), 'CloseRequestFcn', 'closereq'); nowait; close all; clear all; drawnow timers = timerfindall(); if ~isempty(timers) timers = timers(isvalid(timers)); try stop(timers); delete(timers); catc...
0423fc16f5a157ec788dc248f6c2f40be1bdcdec57cc423531f3420726558c8f
MATLAB
381
16
function [biom_name] = find_biom_name(biom) if strcmp(biom,'hoechst') biom_name = 'Hoechst'; elseif strcmp(biom,'sox2') biom_name = 'Sox2'; elseif strcmp(biom,'btub') biom_name = '\beta-tubulin III'; elseif strcmp(biom,'gfap') biom_name = 'GFAP'; elseif strcmp(biom,'map2') biom_name = 'Map2'; elseif...
20e2285b0cf090fd5d2af1bb3e5aed3c3a7fe4c3a9ca6243d9afd74f552cc868
MATLAB
382
19
function get_key(key, laptop_key) % Waits until user presses the key specified in first argument. % Written by KGS Lab % Edited by AS 8/2014 while 1 while 1 [key_is_down, ~, key_code] = KbCheck(laptop_key); if key_is_down break end end pressed_key = KbName(key_code); ...
917145063fd8bde123fe5bfd5e915404a104711ac92d42e4dcb8a7a3ff65e2bf
MATLAB
383
13
function next = create_slice_from_recon_data(input) function slice = create_slice(recon_data) slice.reference = structfun(@(arr) arr(:, 1)', recon_data.bits.buffer.headers, 'UniformOutput', false); slice.data = permute( ... recon_data.bits.buffer.data, ... [4, 1, 2, 3] ... ...
3bbe8b29766c1ad9baa522ff9c384e4e9ef9d61ba556dbf60b03b0ed98691e05
MATLAB
385
12
function nf = framecount(inpict) % NUMFRAMES = FRAMECOUNT(INPICT) % Simple tool to get the number of frames from a 4D multiframe image. % Assumes image dimensioning is [height width channels frames] % The only reason this exists is to make the code descriptive. % % INPICT is an image array of any class % % ...
7c36d7c0f851af7434a9c07ad7e4245cc67592082fb92ee4ecfbdc4833a22f87
MATLAB
386
20
function [SpikeTrialsPSG] = rectifywindownr(cfg,SpikeTrialsPSG) fprintf('sdf\n'); for ipart = 1 : size(SpikeTrialsPSG,2) for itemp = 1 : size(SpikeTrialsPSG{1}.trial,2) temptrials = unique(SpikeTrialsPSG{ipart}.trial{itemp}); for stage = 0 : 5 trialn...
84dd4ab0669806d37a5cd12fc9573a679c15874e4cc76bc576057fda007df590
MATLAB
386
13
function [] = dispAverageImages(images) % input: images should be a cell array, each cell contains a 4-dimensional % image % displays a montage of channel 1, averaged across all images in the cell % array nDims= length(size(images{1})); ImgAverage=mean(cat(nDims+1,images{:}),nDims+1); figure imagesc(stackToMontage(per...
012bea12a8dab555df068e234adb213b6528e93e02cfcdaa609c4428e4d47168
MATLAB
387
17
function verbPrint(verbLvl, verbCut, messOut) % verbPrint(verbLvl, verbCut, messOut) % % Function to output messages at a given level of verbosity % % 2019 - Adam Charles if verbLvl >= verbCut fprintf('%s\n',messOut) end end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%...
e2aadd2b91ab3261726c2421c02d52ab5707f4de6e982a005650f24686015d9e
MATLAB
387
13
function [quantity, center, scale] = centerAndNormalizeRange(quantity, dim) %% Default arguments if nargin < 2 || isempty(dim) dim = 1; end center = mean(quantity, dim, 'omitnan'); scale = 0.5 * (max(quantity,[],dim) - min(quantity,[],dim)); scale( scale == 0 ) = 1; quantity = ...
40466e97f3b0172dcc72eea06d2a78446f2c74fe50df799864ba72c683e3d6c5
MATLAB
388
13
function [PPC]=getPPC(Spikephases) % by Mattia % input % SpikePhases - vector of phases, with respect % to the frequency band of interest SpikephasesMatrix=repmat(Spikephases,length(Spikephases),1); DotProd=cos(SpikephasesMatrix-SpikephasesMatrix'); DotProd(logical(eye(size(DotProd))))=0; SumDotProd=sum(sum(DotProd))...
dfaee162905d1d6a5e6e4881491226dabf4385737960700e766c10e7fbcec5cd
MATLAB
390
14
%% PARSEPATH Consistent file path/name+extension parsing across operating systems. function [nameext, path] = stripPath(path) tokens = regexp(path, '^(.*?)[/\\]*([^/\\]*)?$', 'tokens', 'once'); if iscell(path) tokens = cat(1, tokens{:}); path = tokens(:,1); nameext = tokens(:,2); el...
9b87d82012c74165a56520e41e9ef7136f246cc639dd64e0b5a4dad3004262cf
MATLAB
392
11
function Cor = getCor(result) % calculates the correlation matrix accross parameters %function Cor = getCor(result) % it uses getCov to get the covariance matrix % result should be a result struct which contains the full posterior % Cor then is the correlation matrix Cor = getCov(result); std = sqrt(diag(Cor)); Cor =...
c2eecd79143878efd5d3bbef6ed1c7ea089243b18a050563d95cce68c11ad49d
MATLAB
392
10
%% function to get GD occupancy in each context function HDirOccupancy = HDir_Occupancy(framesToUse, binned_HDir, Nbins, framerate) N_ctxt = length(framesToUse); HDirOccupancy = zeros(Nbins,N_ctxt); % dimensions: angular bins, ctxts, rewards for c = 1:N_ctxt HDirOccupancy(:,c) = histcounts(binned_HDir(fram...
22508506bc320abd1d772f772c8b3b6503b8914b249753dbe63f044a13cef0f5
MATLAB
394
24
% % numCores = findNumberOfCores() % % Description: % find number of available cpu cores % % Input: % % Output: % numCores - number of cpu cores % % Copyright: % 2014-2018 (c) USC Biomedical Imaging Group (BigLab) % Author: % Jian (Andrew) Li % Revision: % 1.0.3 % Date: % 2018/01/22 % funct...
c3ec9abc4508654dab2dc4a6d1dac87725994ab804c5f7782178d3cc62962624
MATLAB
399
18
%% function [varargout] = multiplex(subset, varargin) if max(1,nargout) ~= nargin - 1 error('Number of outputs must be number of inputs minus one'); end varargout = cell(size(varargin)); for iA = 1:numel(varargin) x = varargin{iA}; if numobj(x) > 1 varargout{...
f1f10150204db42a0acd81cb89bbf62d5cdbe3f32b88fa0cb570547dcc626001
MATLAB
399
13
%% function neighborhood = generateNeighborhood(numParticles, numNeighbors) neighborhood = zeros(numParticles, numNeighbors); for i = 1:numParticles startIdx = mod(i - ceil(numNeighbors/2) - 1, numParticles) + 1; for j = 1:numNeighbors neighborIdx = mod(startIdx + j - 1, numParticle...
4852ac0bab12656fe3929141e4be3f6bff702f20ef065a18f552cb16420e3ba2
MATLAB
402
12
function [retval] = fs_fread3(fid) % freesurfer_fread3 - read a 3 byte integer out of a file % % !!! Modified by D. S. Schwarzkopf (15/09/2012) !!! % % [retval] = freesurfer_fread3(fid) % see also freesurfer_write3, freesurfer_read_surf, freesurfer_write_surf b1 = fread(fid, 1, 'uchar') ; b2 = fread(fid, 1, 'uchar')...
7a9db3453a48e8f1f4294f9273e7a0deac06d3373fa2461db5a6c8ad5bc58343
MATLAB
402
23
classdef CCAResults properties A B r U V stats end methods function obj = CCAResults(XMatrix,YMatrix) [A,B,r,U,V,stats] = canoncorr(XMatrix,YMatrix); obj.A = A; obj.B = B; obj.r = r; obj.U = ...
8ef2f724582dd676250d0f9b20f02928f1ce0fdf3067a7d77f8de29e51d80cad
MATLAB
402
15
%% function to calculate PVC function [mean_PVC, PVcorr]= GetPV(popfiringI, popfiringII) [r,c,~] = size(popfiringI); PVcorr = nan(r,c); for i = 1:r for j = 1:c pI = squeeze(popfiringI(i,j,:)); pII = squeeze(popfiringII(i,j,:)); PVcorr(i,j) = nancorr(pI, ...
59d3d37be74956a93b5b6b4bbfaba6d2adbaf59f2716492da97b595000c57f18
MATLAB
403
12
function psi = typeIIRaisedCosineWavelet(t, scale, shift, beta) %% Obtain wavelet from mother t = (2.^scale) .* t - shift - 0.5; T = 2*pi*t; %% Evaluate mother wavelet psi = ( sin( (1 - beta)*T) + sin( (1 + beta)*T) ) ./ (T .* (1 + 4*beta*t)) ... - ( sin(0.5*(1 - beta...
2e91cce44f3b057d8efbd1a707577b6e884a0f46136aa0ada2213c53dbe46b8c
MATLAB
404
9
%% % Row and column indices for a given linear index and matrix dimensions. % The linear index is assumed to go from 1 at (row,column) = (1,1), and % increment in the column-wise direction. function [indices] = toLinearIndex(linearIndex, numCols) rowIndex = floor((linearIndex - 1) / numCols); colIndex ...
682b05f8ed00b23ac2c64dae93037fa34d34e0cce169996103ee60a966ae1fc0
MATLAB
404
20
%% % function [leafs] = getPanelLeafs(pan) if isempty(pan.children) leafs = {{}}; return; end leafs = {}; for iChild = 1:numel(pan.children) subLeafs = getPanelLeafs(pan(iChild)); for iSub = 1:numel(subLeafs) subLeafs{iSub} = [iChild, sub...
e5f7a9f7bb64c44ec35fd1207cf71348be3d5f1064e467a265ce2b467b8425a4
MATLAB
405
11
%% Close most figures (except those with 'persist' in their Tag values) and clear all MEX programs. MCC_TEMP_FIGURES = findall(0, 'Type', 'figure'); MCC_TEMP_FIGURES( arrayfun(@(x) ~isempty(regexp(lower(get(x,'Tag')), '\<persist\>', 'once')), MCC_TEMP_FIGURES) ) = []; set(MCC_TEMP_FIGURES, 'CloseRequestFcn', 'cl...
eaf8837990467653c465061b9b683479e172fe9813ef969304ae59b39dff4011
MATLAB
406
14
% Remove dimensions only if of length 1 at the specified dimension(s), like a targeted squeeze function B = squish(A, dim) Bsize = size(A); % dim = sort(dim); for iDim = numel(dim):-1:1 if numel(Bsize) >= dim(iDim) && Bsize(dim(iDim)) == 1 Bsize = [ Bsize(1:dim(iDim)-1), Bsize(dim(iD...
048ff2490a4186b37350b8a0aa1ab74b492605619f12ecc3814fa9e695c52242
MATLAB
407
28
function [y,tweight]=nt_wpwr(x,w) %[y,tweight]=nt_wpwr(x,w) - weighted power % % y: weighted ssq of x % tweight: total weight % % x: data % w: weight % if nargin<2; w=[]; end x=nt_unfold(x); w=nt_unfold(w); if isempty(w) y=sum(x(:).^2); tweight=numel(x); else x=nt_vecmult(x,w); y=sum(x(:).^2); ...
4c79a67bcaf4f30793c6ec385a7b8e0919e236f72d084cb125c023989665b1b6
MATLAB
408
15
%% function to bin position data of mouse function [BinnedXY, edges] = BinPosition(XY, ArenaSizeCm, binSizeCm) Nbins = ArenaSizeCm/binSizeCm; edges = zeros(Nbins+1,2); BinnedXY =zeros(size(XY)); for i =1:2 edges(:,i) = min(XY(:,i)):(max(XY(:,i))- min(XY(:,i)))/Nbins:max(XY(:,i));...
44eca0d2bfea3f97efae8e7db812ba39465555fc03af714481c20cda0edbb045
MATLAB
410
20
function out = catcellstruct(dim, cellstruct) %% eg = []; for iIn = 1:numel(cellstruct) if ~isempty(cellstruct{iIn}) eg = mstruct(fieldnames(cellstruct{iIn})); end end %% if isempty(eg) out = struct([]); else [cellstruct{cellfun(@isempty, cellstruct...
017287c51e4baddf26b2034d30c3cff0af880a1436db85fa2018eb7c7e833a79
MATLAB
412
22
function [g,a]=ar1nv(x) % AR1NV - Estimate the parameters for an AR(1) model % Syntax: [g,a]=ar1nv(x); % % Input: x - a time series. % % Output: g - estimate of the lag-one autocorrelation. % a - estimate of the noise variance. % (c) Eric Breitenberger x=x(:); N=length(x); m=mean(x); x=x-m; % Lag zero and on...
0599aa1738176952c803933e5dee1880d48d15f83d28de098fcb2448f0fc464a
MATLAB
412
22
function [status, start_time] = start_scan % This code will trigger the 3T GE scanner at CNI using the E-prime trigger % cable. --Michael 09/30/2013 try s = serial('/dev/tty.usbmodem12341', 'BaudRate', 57600); fopen(s); fprintf(s, '[t]'); fclose(s); catch err end if exist('err','var') == 0 sta...
2199d2c99c509ea2927e99cc30c330ad81d9a748c6076b7dfb2a85366be7c363
MATLAB
413
13
% Convert integer representation YYYYMMDD of a date into a string YYYY-MM-DD function str = dateint2str(dateint) %% Extract elements of date from an integer format year = floor(dateint / 1e4); dateint = dateint - year * 1e4; month = floor(dateint / 1e2); day = dateint - month * 1e2;...
b876ad05332cb580098e08d3dd7784313041430c393dd1f4dc886c2e006b5887
MATLAB
415
18
itrial = cfg.representtrials(1) temp = rmfield(TFR_macro_single,'time'); temp.time{1} = TFR_macro_single.time; cfg = []; cfg.time = temp.time; cfg.trials = itrial; cfg.method = 'pchip'; dat_micro_resampled = ft_resampledata(cfg,dat_micro); A = squeeze(TFR_macro_single.powspctrm(1,:,:))'; B = squeeze(dat_micro_resam...
f7b053181de624776b468766fb07adf157699847cfd4cece91cbc53eeaabfc5f
MATLAB
415
20
%% function [varargout] = show(handles) %----- Get figure handles if nargin < 1 handles = findobj('Type', 'Figure'); elseif ischar(handles) handles = findobj('Type', 'Figure', 'Name', handles); end %----- Loop through figures for handle = rowvec(handles) set(handle,...
328064b45d605e4e25978a1bb60b77b22a535b5aae4af7297cc6908b23057f0a
MATLAB
416
18
function psd_area = compute_psd_area(signal,fs,f_range) % signal: Input signal % fs: Sampling frequency params.tapers=[3,5]; [S,f] = mtspectrumc(signal,params); psd=S'; fx=f*fs; idx=fx>f_range(1) & fx<f_range(2); fx=fx(idx); psd=psd(idx); % Take the logarithm of frequency and P...
39d96c7e3f3969ff75e23060bc89464b9d4635642f3819858ce51fc647d58632
MATLAB
416
14
function history = get_history(order) % Computes the number of times a given condition is preceded by all others % assuming a single column input where each row is a condition. % Written by KGS Lab % Edited by AS 8/2014 num_blocks = size(order, 1); num_conds = length(unique(order)); history = zeros(num_conds); for n =...
45c33de4b8cce199c526c6844831dda3c4b2a1d2b55205afb7ae0ac91b17fe46
MATLAB
416
20
function [L,R,k] = curvature(X) N = size(X,1); dims = size(X,2); if dims == 2 X = [X,zeros(N,1)]; end L = zeros(N,1); R = NaN(N,1); k = NaN(N,3); D = NaN(N,3); for i = 2:N-1 [R(i),~,k(i,:),D(i,:)] = circ(X(i,:)',X(i-1,:)',X(i+1,:)'); L(i) = L(i-1)+norm(X(i,:)-X(i-1,:)); end ...
df0c202b002ab75bd99dc9330da718009feb88f0d79271ab71e6be08cf83acb7
MATLAB
416
20
%% function [varargout] = hide(handles) %----- Get figure handles if nargin < 1 handles = findobj('Type', 'Figure'); elseif ischar(handles) handles = findobj('Type', 'Figure', 'Name', handles); end %----- Loop through figures for handle = rowvec(handles) set(handle,...
ff81e44721b35cb3ad4c19dc3d2bf345ec9417f4a3a978343c0eb84f892d5543
MATLAB
417
25
function nii2int16(in_nii, out_nii, normz) if ~exist('normz','var') normz = 1; elseif ischar(normz) normz = str2double(normz); end v=load_nii_BIG_Lab(in_nii); v.hdr.dime.datatype=4; v.hdr.dime.bitpix = 16; %amin=min(v.img(:)); v.img = v.img - amin; v.img=double(v.img); if normz amax = max(v.img(:)); ...
c3989b5f09278f28c206ed15e9185924f90ddd3c8e02d91893a3f67c3cd77821
MATLAB
418
17
%% % Note that the left edges of bins are inclusive and the right edges are % exclusive. function [bin] = findBucket(x, xEdges) % If there is only one bin then can decide immediately if length(xEdges) < 2 bin = 1; return; end dx = xEdges(2) - xEdges(1); bin = 1 + floor(...
6234ec9569efd9e1a47f47a9286986e766a0da4c23b1bc5fa19338a61519429e
MATLAB
420
12
function patch_std(x, ymean, ystd, color) if nargin < 4 color = 'k'; end y = [ymean - ystd; ystd; ystd]'; filled_SD = area(x,y); filled_SD(1).FaceAlpha = 0; filled_SD(2).FaceAlpha = 0.4; filled_SD(3).FaceAlpha = 0.4; filled_SD(1).EdgeColor = 'none'; filled_SD(2).EdgeColor = 'none'; filled_SD(3).EdgeColor = 'none'...
0f1509adfe6c69267d08e19ef5853c64c9f990f0c8f281d441b93c6e60eedb54
MATLAB
422
13
function p = createFigureParser(extraParams) % Create an inputParser with a standard 'Parent' parameter. p = inputParser; addParameter(p, 'Parent', []); % Always include Parent if nargin > 0 && ~isempty(extraParams) for i = 1:2:length(extraParams) name = extraParams{i}; ...
2840aef9037c79fa71b5cbafdab0e31e40d1eb58772b7a7e9fb65174c8e36326
MATLAB
423
18
%% function to get to which reward the HDC is tuned to function [NReward, WhichReward] = GetWhichReward(TunedBin,RewBin) WhichReward = nan(length(TunedBin(:,1)),1); for i = 1:length(TunedBin(:,1)) for r = 1:length(RewBin) if ~isempty(intersect(TunedBin(i,:), RewBin(r))) WhichReward...
b55e7d4039d1020f5b41f54d76d6ae693478ae0c2ea0c44510f2bfd5a4a15233
MATLAB
423
12
% Returns a range [min,max] that covers the input range but with limits rounded to the given resolution function range = roundRange(range, resolution, symmetric) range = [min(range(:)), max(range(:))]; if nargin > 2 && symmetric range = [-1 1]*max(abs(range)); end range(1) = resol...
e8a35e5f85eb39019e3a5bf7cdd3d686bc6763466a185ca84b70191847a85b3e
MATLAB
423
17
%% function [value] = rget(handles, property, fixName, fixValue) fixPrev = rset(handles, fixName, fixValue); if iscell(property) && numel(property) == numel(handles) value = cell(size(handles)); for iH = 1:length(handles) value{iH} = get(handles(iH), property{iH}); end ...
13bd33526a98a766b7cb09e1cacc4bdc1d3969586ea615d8f5b8c905324dfc8e
MATLAB
424
19
function [num] = numobj(x, noCellStr, noStruct) % NUMOBJ Like numel(), but treats strings as a singleton. if nargin < 2 noCellStr = false; end if nargin < 3 noStruct = false; end if ischar(x) ... || (noCellStr && iscellstr(x)) ... || (noS...
e41b79d71a562cf8c545c7a29f371f7afd147c07353fa067b181699786004676
MATLAB
424
16
function x=my_norminv(p,mu,sigma) % implements the most common version of MATLABs norminv function %function x=my_norminv(p,mu,sigma) % ths function computes quantiles of the normal distribution %input: % p = percentage requested % mu = mean of the distribution % sigma = standard deviation % %output: % ...
0f07bf4dcf2e2bd007d110bab0e7b5d4a977e0dda3f2f18d441c57fa95770c07
MATLAB
425
20
function [pathstr, baseName] = fileBaseName( fileName ) % Returns path string & the base name of the fileName (removing multiple % extensions - see remove_extension.m) % % Usage: % [pathstr, baseName ] = file_base_name(fileName) % baseName = file_base_name(fileName) % [pathstr, baseName, ext] = fileparts(file...
a17a768c4a67f1dfad1ca9a88c801f31153bae03200026cd4fcc0b918c9d96e3
MATLAB
425
16
%% function to measure whether vector length is significant function IsSignificant = TestSignificantRV(RVL_distribution_events, RV, pctile_thresh) PercentileThreshold =prctile(RVL_distribution_events, pctile_thresh, 3); [n_cells, ~] = size(PercentileThreshold); IsSignificant=nan(n_cells,3); IsSignificant(:,2:...
c59859f1e2bf31b9581c47649f74e4508d59749008253b280f1adaf9e183ac93
MATLAB
425
20
function [biom_ch] = find_channel_img(biom) %% Find image based on biomarker % @author: speressotti %% channel_order = {'hoechst','sox2','btub','gfap'} if strcmp(biom,'hoechst') biom_ch = 1; elseif strcmp(biom, 'gfap') biom_ch = 2; elseif strcmp(biom,'s...
a8c7724548f0f78d047dd92ade95656a5f4493ecc7756505edc82a7212d83021
MATLAB
427
16
function importfile(fileToRead1) %IMPORTFILE(FILETOREAD1) % Imports data from the specified file % FILETOREAD1: file to read % Auto-generated by MATLAB on 01-Mar-2026 12:54:25 % Import the file newData1 = load('-mat', fileToRead1); % Create new variables in the base workspace from those fields. vars =...
2881693c129a50230e85152c251a79cf2153ce705edc61f7c3eac565775d808e
MATLAB
428
17
ntrial = length(data_all.trial); nchans = length(data_all.label); spikechan = zeros(nchans,1); for i=1:ntrial for j=8:8 % nchans spikechan(j) = spikechan(j) + all(data_all.trial{i}(j,:)==0 | data_all.trial{i}(j,:)==1 | data_all.trial{i}(j,:)==2); if ~all(data_all.trial{i}(j,:)==0 | data_all.trial{i}(j,:)==1 ...
434df9dff97821f05dfe3a15b6f4bfaacc353b058ce3b54fbcec1acc7d65555e
MATLAB
430
21
%% % Safe version of division, whereby 0/0 is taken to be 0. However note % that x/0 where x is nonzero is still infinity. % function z = safediv(x, y, nil) if numel(x) == 1 z = zeros(size(y)); sel = repmat(x ~= 0, size(y)); else z = zeros(size(x)); sel = (x ~= 0); end...
b21a4aaf6184aa72a01186cfb4c060e1e7a15c6f11c26ae8d981b72b7cbc951b
MATLAB
431
14
clc;clear all;close all;restoredefaultpath; %addpath(genpath('/big_disk/ajoshi/coding_ground/bfp/supp_data')) addpath(genpath('/ImagePTE1/ajoshi/code_farm/bfp/src')); %studydir='/ImagePTE1/ajoshi/ADHD_Peking_bfp'; studydir = '/ImagePTE1/ajoshi/maryland_rao_v1_bfp'; sessionid='rest'; a=dir(studydir); for j=1:length(a...
e18d2babfb3c4a90a709a724f759437ad04653371027bb1311ae94de2b0a3382
MATLAB
431
19
%% function [minimum, maximum] = erange(array, exceptTest) % Exclusive minimum and maximum, over all elements except those passing % the exceptTest. if nargin < 2 exceptTest = @iszero; end minimum = nan; maximum = nan; for iX = 1:numel(array) if ~exceptTest(array(iX)) ...
896267ea14bbb976229ef2deee160ec7bda016c897f24a79be32516d06e0fa8c
MATLAB
432
17
%% Preprocessing pipeline % Prerequisite softwares % 1. BrainStorm % 2. EEGLab % 3. EEGLab plugins % Adjust % Cleanline % PrepPipeline % clean_rawdata % % Running preprocessing % 1. Run runPreprocDarpa.m % 2. Remove ICs from Brainstorm (manual inspection) % 3. Run preprocPostICA.mt % 4. (option...
a065e06c1713ca69c9ad1ac6ed77763d49ea7c5c4b8aff0a65ea2c82cb73ce63
MATLAB
435
26
% % units = getByteUnits() % % Description: % get almost all possible units for information storage % % Input: % % Output: % units - the cell array of units % % Copyright: % 2017-2018 (c) USC Biomedical Imaging Group (BigLab) % Author: % Jian (Andrew) Li % Revision: % 1.0.3 % Date: % 2017/05...
3ddc8b81e76740df12a905f9537248c2348e171886b1526dfbe2d447c1c18079
MATLAB
436
12
% Reshapes the input tensor X down to dim number of dimensions. % % Faster version of e.g. X(:,:,:), which is inexplicably slower than reshaping to 3 dimensions. Can % flexibly specify the dimension dim above which all subsequent dimensions are concatenated into % one. function X = remould(X, dim) sz ...
e7e6f984689d3b068b037b86b46a75438679512730af8aa30f398293fd035cca
MATLAB
436
15
%% SAFEACOS acos() with safety against numerical precisions that may cause the argument to have magnitude slightly greater than 1 function angle = safeacos(angle, epsilon) if nargin < 2 epsilon = 1e-6; end excess = abs(angle) - 1; if any(excess(:) > 0) valid = exc...
d9678484089f9034755ac423ff76a4589642f93fd2bf23a74491fd6067a15235
MATLAB
437
20
function [w, center] = doScreen % Opens a full-screen window, sets text properties, and hides the cursor. % Written by KGS Lab % Edited by AS 8/2014 % open window and find center S = Screen('Screens'); screen_num = max(S); [w, rect] = Screen('OpenWindow', screen_num); center = rect(3:4) / 2; % set text properties Scr...
0ad462e09ebd07d7d5d0079e059869e35aac33deeb7a3ed5f6e6019369b61e26
MATLAB
440
15
function runFile(script_filenames) try % Construct the command to run MATLAB script cmd = sprintf('matlab -r "run(''%s'')"', script_filenames); % Execute the command using the system function status = system(cmd); % Check if an error occurred during script execution if status ~= 0 error(...
2738ab11dbff3851a4e5100dbf13d030d2933aad53f0cc6e0debf367280d2921
MATLAB
441
12
function [position] = findlast(array, varargin) % FINDLAST Returns the index of the last item matching the given % criteria. Zero is returned in case there are no matching items. % % Examples: % % findlast(array, value, [comparator = @eq], [outcome = true], [indexRange|veto = []]) % findlast(a...
9d5400f177d526f10fc8411039f8fb83683fcf2dcb2b7a23fcad993771f7521b
MATLAB
442
13
%% Computes a linear scale factor within a given range function scale = linscale(number, numberRange, scaleRange) number = ( number - numberRange(1) ) ... / ( numberRange(2) - numberRange(1) ) ... ; scale = scaleRange(1) ... + ma...
8432517ceadda319f6c14fedc21ef87613832de5b2b49a51036011eea1fc2601
MATLAB
443
12
function label = cblabel(handle, string, varargin) label = get(handle, 'YLabel'); set ( label ... , 'String' , string ... , 'FontSize' , get(0,'DefaultAxesFontSize') ... , 'Rotation' , -90 ... ...
191a31383fe05ed02c9decd13285485afa9b4540fd2ecfb3376e425e4d3b8ed6
MATLAB
444
15
function y = fullRectify(x, minX, maxX, sharpness) y = nan(size(x)); sharpness = 10^sharpness; scale = 1 / log(sharpness); %% Softplus-like functional form for low end sel = 2*x < minX + maxX; y(sel) = minX + log( sharpness.^(x(sel) - minX) + 1 ) * scale; %% Reverse...
ff20c2b34c02d133cd44d014ebe9e50589e462de529c81cd8523552c55d2e18a
MATLAB
444
13
%% Computes a linear scale factor to represent area within a given range function linScale = area2linscale(area, areaRange, scaleRange) area = ( area - areaRange(1) ) ... / ( areaRange(2) - areaRange(1) ) ... ; linScale = scaleRange(1) ... ...
d51655596c819cc658b23a046595f493d4d0fc4f9ba0bf3728c775d2254f7c35
MATLAB
445
20
classdef ImageArray properties data headers meta waveform acq_headers end methods function self = ImageArray(data, headers, meta, waveform, acq_headers) self.data = data; self.headers = headers; self.meta = meta; ...
16195616616ae462382fe6bb13a521c3ec9256193d96ba1fb375c684fc858755
MATLAB
446
12
function [position] = findfirst(array, varargin) % FINDFIRST Returns the index of the first item matching the given % criteria. Zero is returned in case there are no matching items. % % Examples: % % findfirst(array, value, [comparator = @eq], [outcome = true], [indexRange|veto = []]) % findfir...
23aa15b3ae37435a3401aa8d948157d9d1c185a61ea6a63c15cad4e5471e3793
MATLAB
446
24
% % Map from image space to motor space % % Input % pt: [n x 2] points (rows) in motor coordinates % % Output % new_pt: [n x 2] points (rows) in image coordinates function new_pt = space_img_to_motor(pt) if iscell(pt) new_pt = apply_to_nested(pt,@(x)space_img_to_motor(x)); return; end ...
371703ab5ee6d3e59d63eed87e3193c8312b6f387437e964b8956b082f88d286
MATLAB
449
24
% % Map from motor space to image space % % Input % pt: [n x 2] points (rows) in motor coordinates % % Output % new_pt: [n x 2] points (rows) in image coordinates function new_pt = space_motor_to_img(pt) if iscell(pt) new_pt = apply_to_nested(pt,@(x)space_motor_to_img(x)); return; end ...
b75e812fe0aab680a485307103731a4716502861946831c32248c9a9fa1705f9
MATLAB
449
17
%% Sets the units of all relevant graphics children to the given value. function setUnits(parent, units, matchType) if nargin < 3 matchType = '^(axes|uicontrol|uipanel|uitable)$'; end children = findall(parent); for iChild = 1:numel(children) type = get(children(iChild), '...
310f4a60e87ddedf2f51d3893c2eb4e418da4a09187fc815bac90e2c462d171e
MATLAB
450
10
function yeah = strismember(thing,setofthings) % YEAHITIS=STRISMEMBER(STRING,SETOFSTRINGS) % Returns true if the character vector STRING is a member of the % cell array SETOFSTRINGS. This is generally faster than using % ismember() -- about 2x as fast in recent versions, and up to % 50x as fast in older ve...
ad9cd82651a2411432510e8bdbad9757efadb851d0d8f1dbe93a83fa41e1d303
MATLAB
450
13
%% Gergely Tarcsay, 2023. Function to read the minian dataset. c: raw ca trace, s: deconvolved signal, a: spatial footprint, unit_id: cell_id. All are coming from the minian pipeline. function [c,s,a, unit_id] = ReadNCData(rootdir) cd(rootdir) c = ncread("minian_dataset.nc", 'C'); s = ncread("minian_d...
b6f70a289b5b293112b31ac6d64639ef7a82f5cea28dd6e2091be7e49742e8d6
MATLAB
450
19
%% function to cluster with k-means function clusters = GetClusterKMeans(I, fieldBins, k, max_iter) [idx,~] = kmeans(fieldBins, k, "MaxIter",max_iter); %% create maps for individual fields clusters = zeros([size(I) k]); for i =1:k clust_idx = find(idx == i); for j = 1:l...
730f42dc210993ba01c0c7393ca9a57c9570f0717e2c7fa05459f5ca9efcded1
MATLAB
451
17
%% Return a list of struct field names that match the given regular expression pattern; see also regexp() function names = fieldsmatching(S, pattern, invert) names = fieldnames(S); if iscellstr(pattern) sel = ismember(names, pattern); else sel = ~cellfun(@isempty, regexp(names, pattern, 'o...
0b9d0ee920404208a482c97c007af95362f2069ce2f351c66b29f4449f9d0a86
MATLAB
452
17
function [trapz_ints] = delta_sigma_mod(data) %% Calculates the integral between two points % % **Usage:** [trapz_ints] = delta_sigma_mod(data) % % Input(s): % - data : Input data vector (BS data) % Output(s): % - trapz_ints : Integrals using the trapezoidal rule % % Author: R.M.D. Kock, Leiden University...
f6d1f4ebb2653285c161286aaa9679f12ce90dde7cac3c9d4ea2893ed7c953bc
MATLAB
453
22
function y=nt_normpagecol(x,w) % y=nt_normpagecol(x,w) - normalize each column of each page so its weighted msq is 1 % % y: normalized data % % x: data to normalize % w: weight % % Weight should be either a column vector, or a matrix (2D or 3D) of same % size as data. if nargin<2; w=[]; end [m,n,o]=size(x); i...
0a2ba4653888ea0e68150e121303632c41c2f06958fff249c9cd382fa26410f3
MATLAB
455
12
function tif2mat(fname) %function to convert segmented tif file to mat format %fname is the path and name of the segmented tif file imgInfo = imfinfo(fname); N = size(imgInfo,1); for i=1:N, eval(sprintf('channel%d = imread(fname,i);', i)); end save([fname(1:end-4), '.mat'],'channel1','-v7.3') if N>2 for i=2:N, save([...
d910747f6c78cca8ab8a5a97fa7171f21ca96b6ab29a902bbcaf76885f1f7a0a
MATLAB
457
14
function [sf] = myCreateStringToWrite(input); sf =''; for i= 1:length(input) if (length(input{i})> 1) && (isa(input{i}, 'char')~=1) for j=1:length(input{i}) input{i}= input{i} * 1.000000001; % I do not know a clever way to have a uniform data format. sf = sprintf('%s %s\t',sf, ...
e03e7ba66e89762f6382d116b8187a12b13183f0a38f22ee3f14e69f054b406c
MATLAB
457
8
s=readdfs('/home/ajoshi/coding_ground/bfp/supp_data/bci32kright.dfs'); [FaceNormal, FaceArea, FaceCenter, VertexNormal, VertexArea, SuspectFace, NumFacesEachVertex, Duplicated_Faces, Not_Twice_Faces] = tessellation_stats(s,1); s=readdfs('/home/ajoshi/coding_ground/bfp/supp_data/bci32kleft.dfs'); [FaceNormal, FaceAr...
c62114d24eacbb22612cfb92b2debc244a0d84807c998dab3c5aeef13a5a2a51
MATLAB
461
21
%% From http://undocumentedmatlab.com/blog/controlling-callback-re-entrancy/ function flag = isMultipleCall() flag = false; % Get the stack s = dbstack(); if numel(s) <= 2 % Stack too short for a multiple call return end % How many calls to the calling function are in the stack? na...
7e60846c5d29504e348e9ecf1511ca09e5086728843d1888dd4d1fbe088a80c3
MATLAB
463
16
function nt_mark(idx,labels,line_params,text_params) % nt_mark(idx,labels,line_params,text_params) if nargin<2; labels=[]; end ylim=get(gca,'ylim'); for k=1:numel(idx) line([idx(k) idx(k)],[ylim(1),ylim(1)+0.95*(ylim(2)-ylim(1))], 'color', 'r', 'linestyle', '--'); if ~isempty(labels) if k<= numel(lab...
7078cb559d8cf3cb91d26b767438b820129cfefeba36e092a74eadd95885e1bb
MATLAB
465
16
%function to get reward location function RZ_Loc = GetRewLocation(trials, Correct, event, BinnedXY) [~, ~, idxI] = intersect(trials,Correct(:,1)); RZ_frames = event{Correct(idxI,2),2}+1; RZ_xy = BinnedXY(RZ_frames,:); rewI_map = zeros(max(BinnedXY)); for i = 1:length(RZ_xy) rewI_map(RZ_xy(i,2), RZ_xy(i,1))...
2ac37a7f3d14cbb12a35ac42fce5d08797235c5537176885ca3db90d63be50e4
MATLAB
466
1
function y=rms(x, dim) %RMS - Root-mean-square % % y=rms(x): If x is a matrix the rms is calculated columnwise. % y=rms(x,dim): calculate rms according to dim. % % see also nt_bsrms, nt_bsplot % % NoiseTools % if row vector transpose to column if size(x,1) == 1 ; x = x'; end if nargin == 2 if dim == 0; ...
0d78e4e71770055bb47c8271ccf7ba40e6201a21e1c96f309d7796a05582a2a3
MATLAB
468
19
function U = upperTriangular(M, k) %% Default arguments if ~exist('k', 'var') || isempty(k) k = 1; end %% Construct selection vector for one slice of the input tensor mSize = size(M); sel = triu(true(mSize(1:2)), k); %% Apply selection to every slice of the input M = resha...
de1f6c0ab918c03264fe1c4170676b12e7bf5881aaa108f37db37ceffc79ba23
MATLAB
468
18
%% % Online computation of mean. function [newMean, newWeight] = accumulateMean(currentMean, currentWeight, x, weight) if weight == 0 newMean = currentMean; newWeight = currentWeight; else newWeight = weight + currentWeight; newMean = currentMean ... ...
e22961fbbd2ccfd9a94681e762d4e1d02edda43f8bc1f763399e909b07aa3412
MATLAB
468
21
%% % function [color] = desaturate(color, saturation, beta) %% Default arguments if ~exist('saturation', 'var') || isempty(saturation) saturation = 0.5; end if ~exist('beta', 'var') || isempty(beta) beta = 0; end hsv = rgb2hsv(color); if ismatrix(hsv) hsv(:,2...
bad4d0f07988a974a01e555a3ba6372f9d55b0efa51e0a552fcf146c750384fe
MATLAB
470
18
% Make the mexhyp2f1 mex file; % Siyi Deng; 10-10-2013; mex -I. -largeArrayDims -c round.c mex -I. -largeArrayDims -c gamma.c mex -I. -largeArrayDims -c polevl.c mex -I. -largeArrayDims -c psi.c mex -I. -largeArrayDims -c hyp2f1.c if ispc mex -I. -largeArrayDims mexhyp2f1.c gamma.obj hyp2f1.obj pole...
663b88ebb8436afd9549fcab707e08f7b7731351c6dc333e0fc0b08a1bcb59ea
MATLAB
472
20
function p = my_normcdf(x, mu, sigma) %MY_NORMCDF implements the most common case of Matlab's NORMCDF. %function p = my_normcdf(x, mu, sigma) % ths function computes quantiles of the normal distribution %input: % x = point % mu = mean of the distribution % sigma = standard deviation % %output: % p ...
f2935569b1ac29da09b890dcc0ebd956125588d1035bfa90f62730a3788c2150
MATLAB
473
14
%function to get firing pref - heading prob relationship (binned) function [edges, MedianProbRew, ProbRew] = GetBinnedPrefProb(step, Firing_Pref, ProbReward) edges = -1:step:1; binned_pref = discretize(Firing_Pref,edges); MedianProbRew = nan(length(edges)-1,3); ProbRew = cell(length(edges)-1,1); for b = 1:leng...
cfe9a0ce5c69b1425744435deaee87c5e351b2ab3d5e1fb0b0767fa110262b54
MATLAB
474
11
#!/bin/bash #SBATCH --job-name=spyking-circus #SBATCH --partition=bigmem #SBATCH --time=99:99:99 #SBATCH --mem=128G #SBATCH --cpus-per-task=24 #SBATCH --output=/network/lustre/iss01/charpier/analyses/vn_pnh/slurm/%j_%A-%a-%x-output.txt #SBATCH --error=/network/lustre/iss01/charpier/analyses/vn_pnh/slurm/%j_%A-%a-%x-err...
0800fbc9d8b43a2a252e094660e7106e01a7d92b908d3701d471c928772433c6
MATLAB
483
17
function waveform = read_waveform(socket) header = gadgetron.external.readers.decode_waveform_headers(read(socket, 40, 'uint8'), 1); data = read_data(socket, header); waveform = gadgetron.types.Waveform(header, data); end function data = read_data(socket, header) N = header.number_of_sampl...
6e6c2bd5a1338941fdc9a394e098c906e449ecb4d519783613395a2e365356e9
MATLAB
483
29
function max_frame = get_ei_max_frame(ei, start_frame, end_frame, negative) if nargin < 5 logscale=0; end if nargin < 4 negative = true; end if nargin < 3 end_frame = size(ei,2); end if nargin < 2 start_frame = 1; end max_frame = zeros(size(ei,1),1); for e = 1:size(ei,1) if ~negative [...
ff9b84a5c31197c18afc5b4a86ad021233d15aa4215ba72f46e49accd157ec3c
MATLAB
483
21
function outflag = hasipt() % FLAG = HASIPT() % Check whether the current installation has Image Processing Toolbox installed. % State is persistent to reduce cost of repeated calls. % Output is a logical scalar. % for testing purposes enable = true; persistent hasIPT if isempty(hasIPT) hasIPT = license('test', ...