sha256
stringlengths
64
64
language
stringclasses
27 values
size
int32
1
491k
lines
int32
1
21.8k
content
stringlengths
1
200k
06c422f1d65e682aff7a3e783a00c884d1b3ffa946b0baa12788e9c610c29188
MATLAB
272
8
function [tspks] = poissonP(r,T) %POISSONP Poisson process for generating stochastic spike trains % Computes spike times for given rate(r) in Hz over total time(T) in s dt = 0.0001; % .1 ms precision spks=zeros(1,T*(1/dt)); R=rand(size(spks)); tspks=find(R<r*dt)/10; end
a0f9f878d5b4e9673b352ff5812e289dcf91948c103837865cff44def5248439
MATLAB
272
15
function text = int2ordinal(num) text = int2str(num); switch text(end) case '1' text = [text 'st']; case '2' text = [text 'nd']; case '3' text = [text 'rd']; otherwise text = [text 'th']; end end
82954d81cb56e5f8c0c7d8e2c948eac4202bb5b9d17eb525be64c775eef59cda
MATLAB
275
12
function out = refreshWorkspaceBrowser() saWhos = evalin( 'caller', 'whos' ); for ii = 1 : numel( saWhos ), if strcmp( saWhos(ii).class, '(unassigned)' ), evalin( 'caller', [ saWhos(ii).name, '=[];' ] ), end end out = []; end
f74fc20063a14f2191fdf016ba5756178f87c2fe970f772a33b9e9cec3dfcdfe
MATLAB
275
18
function str = capitalize(str, option) if nargin < 2 option = 'first'; end str = char(str); switch option case 'all' idx = regexp([' ' str],'(?<=\s+)\S','start')-1; otherwise idx = 1; end if ~isempty(str) str(idx) = upper(str(idx)); end end
18a2328e88a9e5e79019501318f1326bd2b0aa550a98e3daf18866d82a02d46a
MATLAB
277
11
function [color] = pastelize(color, gamma, beta) if ~exist('gamma', 'var') || isempty(gamma) gamma = [0.2,0.8]; end if ~exist('beta', 'var') || isempty(beta) beta = 0.6; end color = brighten( imadjust(color, [0;1], gamma), beta ); end
4da027bb19560d4bb0292e8a1d1aed4450dd72b1c95c50ce3bffc7e6cc5e1839
MATLAB
277
13
%% function [minimum] = emin(array, exceptTest) % Exclusive minimum, over all elements except those passing the % exceptTest. if nargin < 2 exceptTest = @iszero; end array(exceptTest(array)) = nan; minimum = rmin(array); end
5e25e6feeae8f227f75baa828a4fb9f7a0c56c5a7aa2f35bcbefa5af31d51d8c
MATLAB
279
13
function index = getMonitorBySize(isLargest) if nargin < 1 isLargest = true; end %% fcnSel = {@min, @max}; monitors = get(0,'monitor'); screenArea = prod( monitors(:,3:end), 2 ); [~,index] = fcnSel{isLargest+1}(screenArea); end
8aafa0cef70447e58e1b02595a45cbc0287bf6b21ada8e20658732e045238d43
MATLAB
279
14
function [sz] = arraysize(x, noCellStr) % ARRAYSIZE Like size(), but treats strings as a singleton. if nargin < 2 noCellStr = false; end if ischar(x) || (noCellStr && iscellstr(x)) sz = [1 1]; else sz = size(x); end end
d87574998354d325acb55632d448af0d1517587b5e4574094156617d7ad48cde
MATLAB
280
9
% Like ctranspose(), except that slices (3rd and higher dimensions) are supported. function T = ctranspose3(A) szA = size(A); A = reshape(A, [szA(1:2), prod(szA(3:end))]); T = permute(A, [2 1 3]); T = reshape(T, [szA([2 1]), szA(3:end)]); end
1c0edd585fada3e705692cb4d4e9ef8d2b5c750a88048daa14d8543a4b3a7f04
MATLAB
282
7
if ispc() mex -v mexlf.c liblfev.c liblocf.c libmut_win.c libtube.c mlfut.c mex -v mexpp.c liblfev.c liblocf.c libmut_win.c libtube.c mlfut.c else mex -v mexlf.c liblfev.c liblocf.c libmut.c libtube.c mlfut.c mex -v mexpp.c liblfev.c liblocf.c libmut.c libtube.c mlfut.c end
d16bbd3ac17b3379fd22d933b701dc9ecd10c02b1efa748935a87cc7a16c07ed
MATLAB
285
13
function p=my_t1cdf(x) % cumulative distribution function of a t-dist. with 1 degree of freedom %function p=my_t1cdf(x) %input % x = point %output % p = cumulative probability % %see also: tcdf xsq=x.*x; p = betainc(1 ./ (1 + xsq), 1/2, 1/2, 'lower') / 2; p(x>0)=1-p(x>0);
43ca8a9e3321b905abb62d785481e257aac48ebdf4554704fe8c76e9ccb6ee01
MATLAB
291
9
function CI95 = ConfInt95(data, dim) % calculates the 95% confidence interval of input data along dimension dim % So, if observations are rows and variables are columns, then call % ConfInf95(data, 1) stdev = std(data, 0, dim); N = size(data, dim); CI95 = stdev/sqrt(N)*tinv(0.975,N-1); end
862ffaf914919be4e83c34d390d4edb615634f89829b616c432ba9c9acd65551
MATLAB
291
8
function [ x ] = ctransform(x) % CTRANSFORM Copula transformation (empirical CDF) % cx = ctransform(x) returns the empirical CDF value along the first % axis of x. Data is ranked and scaled within [0 1] (open interval). [~,x] = sort(x, 1); [~,x] = sort(x, 1); x = x / (size(x, 1) + 1);
213b90ed07705ada228888fea65c7c6808dc46dc02f08fa17af5a5684e189fce
MATLAB
293
14
function cv2 = cv2(array) %only for arrays with one raw if size(array,1) > 1 error('input array dimension must be 1xN') end if size(array,2)>2 for i = 1:length(array)-1 cv2(i) = 2*abs(array(1,i)-array(1,i+1))/(array(1,i)+array(1,i+1)); end else cv2 = NaN; end
e97acab032422ad5283cb39ed6deb040bc80ad4b0a462d843ad559106cc1ccac
MATLAB
296
8
% Oversample the given tCenter vector so that it has points at all bin edges as well as centers function tPoints = toBinPoints(tCenter) tPoints = (tCenter(1:end-1) + tCenter(2:end)) / 2; tPoints = [tCenter(1:end-1); tPoints]; tPoints = [tPoints(:); tCenter(end)]; end
52d44e66d22cfe3341eaac2deeecb48fbd5fb3162dc8d485284a7a13534729cd
MATLAB
297
16
%% function [varargout] = getrange(items, dim) if nargin < 2 range = [ rmin(items), rmax(items) ]; else range = concat( min(items,[],dim), max(items,[],dim) ); end if nargout < 2 varargout = {range}; else varargout = num2cell(range); end end
2190c9db15292e33c6950cea272837c3537790d164b32a040bf6c8f328c0ee63
MATLAB
298
20
function yes = makeDirectory(path) if exist(path, 'dir') yes = false; return; end [dir,~,ext] = fileparts(path); if ~isempty(ext) path = dir; end if exist(path, 'dir') yes = false; else yes = true; mkdir(path); end end
669ad2fe76b787ddc2f646a784d9f078f263251dbfd693941309dba26b27a918
MATLAB
298
13
%% function to bin goal-direction with from -pi to +pi function [binned_GD, binCenter] = BinHDir(HDir, edges) binned_GD = discretize(HDir, edges); Nbins = length(edges)-1; binCenter = zeros(Nbins,1); bw = (edges(2)-edges(1))/2; for i = 1:Nbins binCenter(i) = bw+edges(i); end end
16a8b8eb6ae50910fe1ff6e3c0dcd58e2ea99c08fcd0ce8ba2a7bc3e6af25b02
MATLAB
299
19
function str = sigprint(p) str = cell(size(p)); for iP = 1:length(p) if p(iP) <= 0.001 str{iP} = '***'; elseif p(iP) <= 0.01 str{iP} = '**'; elseif p(iP) <= 0.05 str{iP} = '*'; else str{iP} = ''; end end if length(p)==1 str = str{1}; end end
865c8c360ca6278c704a95b4f3bc21e60d2ab2f67eb70ba3858afd4ff88fb90b
MATLAB
299
11
function result = meanExclDiag(sqMatrix) % Get the mean of a square matrix excluding the diagonal, and % excluding NaN's dim = size(sqMatrix); if (length(dim)~=2)||(dim(1)~=dim(2)) disp(dim); error('input is not a square matrix'); end dim = dim(1); result = nanmean(sqMatrix(~eye(dim))); end
a5ecfaa0615730a135338fa62a0826a94db2cbc168b5a9491acaafcb14e6c12d
MATLAB
299
25
classdef PLSData properties XS; avgXS; YS; avgYS; XL; avgXL; YL; avgYL; PCTVAR; avgPCTVAR; MSE; avgMSE; R2; avgR2; RMSE avgRMSE; y_test; y_pred; end end
bff65b743671f5583f6cdfad6129000571af61f6b2275f6928e652d07c819494
MATLAB
299
13
function combineSurfVolGOrdfMRI(GOrdSurfFile,GOrdVolFile,GOrdFile) load(GOrdSurfFile); load(GOrdVolFile); lsz=size(left_GO_fMRI,1); rsz=size(right_GO_fMRI,1); GO_fmri=Vol_GO_fmri; GO_fmri(1:lsz,:)=left_GO_fMRI; GO_fmri(1+lsz:lsz+rsz,:)=right_GO_fMRI; dtseries=GO_fmri; save(GOrdFile,'dtseries');
ece25a11096dc39595ab3353bc447b7b4810288c8de38bdd339d882c895ef2ce
MATLAB
303
9
%% Linearly interpolated (in CDF) quantiles. function quantile = inverseCDF(x, probability) [cdf,value] = ecdf(double(x)); value = value(2:end); cdf = ( cdf(1:end-1) + cdf(2:end) ) / 2; quantile = interp1(cdf, value, probability, 'linear', 'extrap'); end
737aa29abc7496f7cc917002856e63f1e9c6c3d2f472fd1b3121dbab0fed8a2d
MATLAB
304
15
%% function [handles] = vcf(varargin) if nargin > 0 && all(ishghandle(varargin{1})) handles = varargin{1}; iOption = 2; else handles = 0; iOption = 1; end handles = findobj(handles, 'Type', 'Figure', 'Visible', 'on', varargin{iOption:end}); end
cf9815463b495e728ee2604a5e42aacf0cfcab1b113e484ca39ef4c169696692
MATLAB
305
14
%% function [rMax] = rangemax(range1, range2) if numel(range2) == 1 rMax = [ min([range1(1) range2]) ... , max([range1(2) range2]) ... ]; else rMax = [ min([range1(1) range2(1)]) ... , max([range1(2) range2(2)]) ... ]; end end
d9287c25cd3ff38b4737043ac7b9d81a01733b9e0495231d7847ebf8b7361f6b
MATLAB
305
12
function [target] = addstruct(target, varargin) % ADDSTRUCT Adds all fields in subsequent structs to target. for iArg = 1:numel(varargin) input = varargin{iArg}; for field = rowvec(fieldnames(input)) target.(field{:}) = input.(field{:}); end end end
2c659532c42d9bc9f423cf814576c3e00942fe76366b5893b8b018932d52764f
MATLAB
306
19
%% function X=initialization(N,Dim,UB,LB) B_no= size(UB,2); % numnber of boundaries if B_no==1 X=rand(N,Dim).*(UB-LB)+LB; end % If each variable has a different lb and ub if B_no>1 for i=1:Dim Ub_i=UB(i); Lb_i=LB(i); X(:,i)=rand(N,1).*(Ub_i-Lb_i)+Lb_i; end end
b2b3f3292660d146669234dfe5d57c34174c0004b55c3f2e3fb022cb46d0c3dc
MATLAB
308
15
function [range, index] = maxrange(varargin) % MAXRANGE Finds the range with the maximum span. narginchk(1, inf); index = 1; for iArg = 2:nargin if span(varargin{iArg}) > span(varargin{index}) index = iArg; end end range = varargin{index}; end
ccfd8138c0223e1d2f4cd56d843ea0e604abeb59dff64da2232aaa50f7a60d0a
MATLAB
308
9
function quietwarning(varargin) % QUIETWARNING(MESSAGE) % Print a simple warning message with backtrace momentarily disabled. % That's all this does; other functionality of warning() not supported. S = warning('query','backtrace'); warning off backtrace warning(varargin{:}) warning(S.state,'backtrace')
20912f8e2a65727e8a1de6d7c6294715cd2e88985bff3b5409a5e54d6d485d29
MATLAB
309
9
%% function to get mean event rate of HDC cells function MeanRate = GetMeanRateHDC(HD_list, HD_table, HDir_Rate) MeanRate = nan(length(HD_list),1); for i = 1:length(HD_list) idx = find(HD_table.cellID == HD_list(i)); MeanRate(i) = mean(HDir_Rate(idx,:,:),"all"); end end
229930b0729e412be31596d3f90c455ff1fc6ae8e38d9e36fe52e65146f1d75b
MATLAB
309
8
function string = csprintf(format, color, varargin) string = sprintf ( '{\\color[rgb]{%.3g %.3g %.3g}%s}' ... , color(1), color(2), color(3) ... , sprintf(format, varargin{:}) ... ); end
2a9c8bc0182b1a87896b04e86859643b3be92957caddcc42c75bb7eb7d5c292e
MATLAB
310
13
% Returns all current axes in the given figure, or all figures by default function axs = allaxes(fig) if nargin < 1 fig = findall(0, 'Type', 'Figure'); end axs = gobjects(size(fig)); for iFig = 1:numel(fig) axs(iFig) = get(fig(iFig), 'CurrentAxes'); end end
1b0a336885cce2c3fb3c95389e9c57e41ac8cd9e044a48510ea9ee1aa09ca7c3
MATLAB
312
14
% Replace all instances of old by new in a numeric array A; supports NaNs function A = numrep(A, old, new) %% Find all elements of A that matches old if isnan(old) sel = isnan(A); else sel = bsxfun(@eq, A, old); end %% Replace selected elements A(sel) = new; end
20104dbac1bc7cf7afedd5754a99081a46665a75e58ce3897c99f8a7dbb2c88a
MATLAB
313
14
% Returns the current axes in the given figure if there is one, otherwise returns an empty graphics array function axs = curraxes(fig) if nargin < 1 fig = get(0,'CurrentFigure'); end if isempty(fig) axs = gobjects(0); else axs = get(fig, 'CurrentAxes'); end end
25fe839b9a1206f3a40718238cd0b1dcbd38cdd035d42fd7d3d600185e494bbd
MATLAB
313
14
%% function [handles] = vca(varargin) if nargin > 0 && all(ishghandle(varargin{1})) handles = varargin{1}; iOption = 2; else handles = vcf; iOption = 1; end handles = findobj(handles, 'Type', 'Axes', 'Visible', 'on', 'Tag', '', varargin{iOption:end}); end
66f5dc3495de5e8876b8924aabcb068fa154f13d7b22db38c19f56ac2d282451
MATLAB
313
10
function out = mdphasescramble(md); nframes = size(md,1); nmarkers = size(md,2); r = round(rand(1,nmarkers)*nframes); for i=1:nmarkers h = md(1:r(i),i,:); md(1:nframes-r(i),i,:) = md(end-nframes+r(i)+1:end,i,:); md(nframes-r(i)+1:end,i,:) = h; end; out=md;
f9c925b4c35201b49718b09f8055ae4ce1d5bf3d9c6ae6340403125f02515c0d
MATLAB
313
14
%% function [previousValue] = rset(handles, property, value) previousValue = get(handles, property); if iscell(value) && numel(value) == numel(handles) for iH = 1:length(handles) set(handles(iH), property, value{iH}); end else set(handles, property, value); end end
75af4df5bd4d2d23d143650c8d66c32c34b4959278dd7c8f5476a8dc49911283
MATLAB
315
13
function datz = nanznorm(datin) for rowi = 1 : size(datin,1) dat = datin(rowi,:); if any(isnan(dat(:))) xmu=nanmean(dat); xsigma=nanstd(dat); datz(rowi,:) = (dat-repmat(xmu,size(dat,1),1))./repmat(xsigma,size(dat,1),1); else datz(rowi,:) = zscore(dat); end end
ee648acfa1358dcd6c7711ea073a3c69467bd68207c24ffa824ac95aaf8b9a12
MATLAB
315
14
% % Input % I: binary image (black = true) % function plot_image_only(I) assert(size(I,1)==105); assert(size(I,2)==105); newI = 1-I; newI(isinf(I)) = 0.5; image([1 105],[1 105],repmat(newI,[1 1 3])); set(gca,'YDir','reverse','XTick',[],'YTick',[]); xlim([1 105]); ylim([1 105]); end
f47f2a7ca668691ca028b96e73633b2e5237c0c46e6f6aad3cdc0a7c089e9054
MATLAB
316
10
function mask = diskMask(maskWidth, maskHeight, maskRadius, maskCenter) if nargin < 4 maskCenter = ([maskWidth, maskHeight] + 1) / 2; end [col, row] = meshgrid(1:maskWidth, 1:maskHeight); mask = ( (col - maskCenter(1)).^2 + (row - maskCenter(2)).^2 ) <= maskRadius^2; end
3b514f2e8ed2fbd6f0e013a763f580b235a7b54efe51c86afee42eedbb118d5f
MATLAB
317
9
%% Function to get firing preference that are located in reward zone function FiringPref = GetFiringPref(vec1,vec2,RewZone) FiringPref = nan(length(vec1),1); for i =1:2 idx = find(RewZone == i); FiringPref(idx) = (vec1(idx)-vec2(idx))./(vec1(idx)+vec2(idx)) * (-1).^(i+1); end end
5be13fa826fef1c5edd7b0ca18db7aa9d078b4aa69c7fd8d012492d7216dc3e5
MATLAB
317
13
function generateSurfGOrdfMRI(GOrdIndFile,fmri2surfFile,GOrdsurfFile) % Tells the compiler that parallel processing is required %#function gcp load(GOrdIndFile); load(fmri2surfFile); left_GO_fMRI=datal_atlas(ind_left,:); right_GO_fMRI=datar_atlas(ind_right,:); save(GOrdsurfFile,'left_GO_fMRI','right_GO_fMRI');
f520a76ba306ccbc640ddde713c94d406f2efa0559c56ea38660685238efe517
MATLAB
317
11
%% % Converts the given structure x to an argument list % {name1, value1, name2, value2, ...} % Additional name/value pairs can be provided to be concatenated to this % list. function [y] = struct2arg(x, varargin) y = rowvec([fieldnames(x), struct2cell(x)]'); y = [y, varargin]; end
0c9462a15142f5f66b883a7be48afda28106e83abbbc409ebd6bc55c9ab0ea08
MATLAB
318
15
function [y, dydx] = softPlus(x, sharpness) %% Default arguments if nargin < 2 || isempty(sharpness) sharpness = 1; end %% Smoothly rectified output expkx = exp(sharpness * x); y = log(1 + expkx) / sharpness; if nargout > 1 dydx = expkx ./ (1 + expkx); end end
dd2547cf0b2b29d9b478be8f14dca0e6c1bbe7d0a124b117de76f6415bfb7c5d
MATLAB
318
10
function factors = getFactors(number, basis) factors = nan(numel(number), numel(basis)); remainder = number; for iBase = 1:numel(basis) factors(:,iBase) = floor(remainder ./ basis(iBase)); remainder = remainder - factors(:,iBase) .* basis(iBase); end end
73dc1a56cd56fc64c17ee428a3381ced652dfcb32a8c392a6888630b22cc8a8a
MATLAB
319
12
function [dmeg, dspc] = block_delay(bmeg, bspc, d) Nblock = length(bmeg); dmeg = cell(Nblock,1); dspc = cell(Nblock,1); for bi=1:Nblock common = min(size(bmeg{bi},1),length(bspc{bi})); dmeg{bi} = bmeg{bi}((1+d):common,:); dspc{bi} = bspc{bi}(1:(common-d)); end dmeg = cell2mat(dmeg); dspc = cell2mat(dspc);
f029331f5bc63eea5073695593f5b02e49b84e8ba08d177dc7e9adc3737ad137
MATLAB
319
14
%% function [rMax] = rangemax(range1, range2) if numel(range2) == 1 rMax = [ min([range1(1) range2]) ... , max([range1(2) range2]) ... ]; else rMax = [ min([range1(1) range2(1)]) ... , max([range1(2) range2(2)]) ... ]; end end
66f52f50903de1c4fac8cdfc21aac411fda5d92864fc6d62683b2da763a35d74
MATLAB
321
14
function q = fdr_bh(p) % Benjamini-Hochberg [p_sorted, sort_idx] = sort(p); n = length(p); q_sorted = p_sorted .* n ./ (1:n)'; q_sorted = min(1, q_sorted); for i = n-1:-1:1 q_sorted(i) = min(q_sorted(i), q_sorted(i+1)); end q = zeros(size(p)); q(sort_idx) = q_sorted; en...
bfc918705f88161682964bc009cc2c9782f05ef3f7fe1123bf72549ec0ba56fc
MATLAB
322
12
function [yes] = isstrings(x) % ISSTRINGS Returns true if the given object(s) are character arrays or % cells of character arrays. yes = false(arraysize(x, true)); for iX = 1:numobj(x, true) obj = at(x, iX, true); yes(iX) = ischar(obj) || iscellstr(obj); end end ...
57921d6e16fe04a02e69bc70114e9a442e6b0cfe0aa47cf7359e28364aecd7dc
MATLAB
325
12
% Insert dimensions of length 1 at the specified dimension(s), like the opposite of squeeze function B = fatten(A, dim) Bsize = size(A); % dim = sort(dim); for iDim = 1:numel(dim) Bsize = [ Bsize(1:dim(iDim)-1), 1, Bsize(dim(iDim):end) ]; end B = reshape(A, Bsize); ...
2d153ab4f4edacf6931426fd48484ed40990919a0f4cf2715e545c8e475b6095
MATLAB
327
7
%TERRAIN green-brown colormap function map = terrain(varargin) % map = [0 40 42; 10 120 10; 80 150 0; 150 100 0; 220 150 0]/255; % map = [0 0 50; 0 80 100; 50 160 0; 120 120 0; 160 80 0; 220 160 0]/255; map = [0 0 120; 0 100 100; 50 160 0; 120 120 0; 160 80 0; 220 160 0]/255; map = colormap_helper(map, varargin...
240728fc893d7ef1fe048ff035755a18601caa40402ce259bec649c0f5822572
MATLAB
328
8
% Converts the given array of elements into a vector along dimension dim, i.e. the output will be an % array of size 1 in all dimensions other than dim, which will have all the input elements. function v = vecD(elements, dim) vSize = [ones(1, dim-1), numel(elements), 1]; v = reshape(elements, vSize); ...
c14db8b0ea5e05957e49ab09db8b802baa9923ce1ad87b56a491863e104f182d
MATLAB
328
19
function x=nt_normrow(x) % y=nt_normcol(x) - normalize each row so its msq is 1 % % y: normalized data % % x: data to normalize % if ndims(x)>2 s=size(x); x=nt_normrow(reshape(x,[x,prod(s(2:end))])); x=reshape(x,s); else w=1./sqrt(mean(x.^2,2)); w(find(isnan(w)))=0; x=bsxfun(@times,x,w); e...
c5e799e9917f7ae488a70f7fe0ad3841bb643dc6d85b75e8b429c37a62d63e90
MATLAB
329
12
function str = camelCase(str) if iscell(str) for iStr = 1:numel(str) str{iStr} = regexprep(str{iStr}, '[^a-zA-Z0-9]*([a-zA-Z0-9]+)[^a-zA-Z0-9]*', '${titleCase($1)}'); end elseif ~isempty(str) str = regexprep(str, '[^a-zA-Z0-9]*([a-zA-Z0-9]+)[^a-zA-Z0-9]*', '${titleCase($1)}'); end...
e4f53df9fcd92c29a5c5940c2e64d06fef48ef2397b82cf1668a5edc092bba16
MATLAB
329
11
% Convert spans [n1, n2, ...] to ranges {1:n1, n1+1:n1+n2, ...} function index = span2index(span) %% If a vector is provided, assume that it's the count of items in each span if isvector(span) endPoints = cumsum(span(:)); span = [1; endPoints(:)+1]; end index = range2index(span); ...
32a01a453e0d5d1dfbb4116886d4a9beef6ee1c820b591a23288f3c53527f467
MATLAB
330
14
function pvalue = empiricalPvalue_abs(empiricalDist, observedValue) arguments empiricalDist (:,:) double observedValue (1,1) double end N = numel(empiricalDist); empiricalDist_abs = abs(empiricalDist); observedValue_abs = abs(observedValue); k = sum(empiricalDist_abs >= observedValue_abs); pvalue = (k+1) / (N...
98dd008c8e4865f16b583065fa483399c41beeffe6ca037b3e858e7a69ce0fc1
MATLAB
331
11
function txt = sciFormat(number, precision) if nargin < 2 || isempty(precision) precision = '%.3g'; elseif isnumeric(precision) precision = sprintf('%%.%dg',precision); end txt = sprintf(precision, number); txt = regexprep(txt, 'e(-?)0*([0-9]+)', '\\times10^{$1$2}');...
e815e7d06af069f63b95d71fb4c74a136ca7e3bb3062cf62179dcf07a3c0d3c5
MATLAB
331
12
function ftDataOut = reselect_channels(ftData,channelInfo) % Select only for channels that are connected validChannels = strtrim(cellstr(num2str(channelInfo.Channel))); validChannels = strcat('LFPx',validChannels); % Now select subset cfg = []; cfg.channel = validChannels; ftDataOut = ft_selectdata(cfg, ftDa...
0d9d0e73e90537c2425e946ff91fb83b743c9b87b67df3743cd817c207f82361
MATLAB
332
10
function x = copnorm(x) % COPNORM Copula normalisation % cx = copnorm(x) returns standard normal samples with the same empirical % CDF value as the input. Operates along the first axis. % Equivalent to cx = norminv(ctransform(x)) % [~,x] = sort(x, 1); [~,x] = sort(x, 1); x = x / (size(x, 1) + 1); x = -sqrt(2).*er...
34da0bf37e9bc9a310540afe730025fe2fe2cbe2e540c6b40f65a96d4a46130e
MATLAB
333
10
function fmap = cpp_mex_default_function_map() fmap = struct( ... 'copnorm_slice', 'copnorm_slice_cpp', ... 'info_cc_slice', 'info_cc_slice_cpp', ... 'info_cc_multi', '', ... 'info_cc_slice_indexed', '', ... 'info_c1d_slice', '', ... 'info_cd_slice', 'info_cd_slice_cpp', ... 'info_dc_slice_b...
34dd73007dee573cd4b534ba6b62b2b077986474fc7e653d60b8149366a8ace7
MATLAB
333
13
% Like figure(), but accepts a resizing factor. function fig = sfigure(scale, varargin) if nargin < 1 scale = 0.6; end fig = figure(varargin{:}); pos = get(fig, 'Position'); pos(3:end) = pos(3:end) .* scale(:)'; pos(3:end) = max(pos(3:end), 1); set(fig, 'Position', pos...
781a97e28dcb5bf87fc8d02749e4fe4b7336fc43d646b7f66f7abc348e6aca34
MATLAB
335
18
function [minval maxval] = imrange(inpict) % [min max] = IMRANGE(INPICT) % returns the global min and max pixel values in INPICT % % INPICT can be a vector or array of any dimension or class x = inpict(:); minval = double(min(x)); maxval = double(max(x)); if nargout < 2 minval = cat(2,minval,maxval...
63c5df7ad4bc03589ec0bc209455583224f93e35122d13fab78b242db6411e17
MATLAB
336
13
function [dataWithoutNaNs] = remove_nans(data) %% remove nans from array dataWithoutNaNs = []; for col = 1:size(data, 2) columnData = data(:, col); columnData(isnan(columnData)) = []; dataWithoutNaNs(1:size(columnData,1),col) = columnData; end dataWithoutNaNs(dataWithoutNaNs ==...
81722a9f410e8102e4f8aff7ac87e367b85081eb3be5afa0f5a66eeb85001a19
MATLAB
336
14
%% function to get bin where HDC tuned to function TunedBin = GetTuningBin(HD_list, HD_table) TunedBin = zeros(length(HD_list),2); for i = 1:length(HD_list) idx = find(HD_table.cellID == HD_list(i)); TunedBin(i,:) = HD_table.IsPC_HDC(idx,2:3).*HD_table.RVMeanBin(idx,:); end TunedBin(TunedBin == ...
b120bc272524f80139dd5d46debef05bf402f2ec8f15f51c395e65e6deae9512
MATLAB
336
13
%% % Computes a profile of a histogram over a given dimension. % Todo: optionally also compute the spread % function [profile] = hprofile(histo, dimension) profile = sum(histo, dimension); counts = sum(histo > 0, dimension); profile = profile ./ max(counts, 1); profile = squeeze(profile)...
0ddad0e8356fcfd4eb696c616aed5464fc976a0c148df62adda6413e26b9f8cc
MATLAB
337
21
function ExcelPrint(prefix,filename,T) mydir=cd; if isdir([mydir '/Data'])==0 mkdir('Data') else end newname=strjoin([prefix,'_',filename,'.csv']); if newname{1}(1)=="_" newname=string(newname{1}(2:end)); end a= [cd,'\Data']; mydir=cd; cd(a) writetable(T,newname,'WriteVariableNames',false); cd...
1f996d084a770685c389cb9335511a6422ccad24a49dbf5bce06ac9811a89a4d
MATLAB
338
8
function [psth, centers] = return_histogram(spk_times, t_span, n_trials, smooth_win) edges = 0:1:t_span; centers = (edges(1:end-1)+edges(2:end))/2; counts = histcounts(spk_times, edges); counts = counts/n_trials; sm_wind = hanning(smooth_win); % gausswin(smooth_win,smooth_win/10); psth = conv(counts, sm_wind, 'same')...
5e2fda245413d5f0dc5298f2fdd6de8ec61868888e0ef195ea2505d51c3f92b9
MATLAB
338
17
function [s] = var2struct(varargin) % VAR2STRUCT Returns a struct containing all input variables. s = struct; if nargin < 1 return; end s = repmat(s, size(varargin{1})); for iArg = 1:nargin values = num2cell(varargin{iArg}); [s.(inputname(iArg))] = values{:};...
7b3857236c688a4d114b5926650009997ebb643873dd2381e4f1070deda4dd87
MATLAB
338
14
% Pregenerate filter weights function kernel = gaussianKernel1D(kernelWidth, dx, nSigmas) if nargin < 2 dx = 1; end if nargin < 3 nSigmas = 4; end kernel = normpdf(-nSigmas*kernelWidth:dx:nSigmas*kernelWidth, 0, kernelWidth); kernel = kernel / sum(ke...
d96551e5f4757ab3285ccdd9f4a1883eb4907dbd91efdbafbf7bff7ef694f4c2
MATLAB
338
17
%% % Separates inputs into two lists based on the provided test. % function [pass, fail] = separate(test, varargin) pass = varargin; fail = varargin; for iArg = length(varargin):-1:1 if test(varargin{iArg}) fail(iArg) = []; else pass(iArg) = []; end ...
fba14621f33d7c142c3123184b125de1ff35ebb57eadb55cc86a375d16e61369
MATLAB
338
16
%% % Recursively runs max() on an input tensor, returning the maximum over all % element in all directions. function [x, i] = rmax(tensor, dimensions) if nargin < 2 [x, i] = max(tensor(:)); else x = tensor; for iD = 1:numel(dimensions) x = max(x, [], dimensions(iD)); end...
0b880f45e87a004cbbb0dcb303cabfdb9599aaacbdd223f24bc53f692dc1a161
MATLAB
339
17
%% % Returns entries that have a significant amplitude relative to the maximum. % function [x] = chopped(x, epsilon) if nargin < 2 epsilon = 1e-10; end if numel(x) > 1 big = ( abs(x) >= epsilon * (rmax(x) - rmin(x)) ); else big = ( abs(x) >= epsilon ); end x =...
148394fe38e45fcfb4eefd58e63f41ed0ff2aec53570ab109e9586a15a4a0fad
MATLAB
339
17
%% function [maximum] = emax(array, exceptTest) % Exclusive maximum, over all elements except those passing the % exceptTest. if nargin < 2 exceptTest = @iszero; end maximum = nan; for iX = 1:numel(array) if ~exceptTest(array(iX)) maximum = max(maximum, array(iX)); en...
2478558716192b40f7f10bbc9d8d2bca3922bd8a004e9990c128f22541862e81
MATLAB
340
16
function z = entropy(x) % Compute entropy z=H(x) of a discrete variable x. % Input: % x: a integer vectors % Output: % z: entropy z=H(x) % Written by Mo Chen (sth4nth@gmail.com). if ~isempty(x) n = numel(x); [~,~,x] = unique(x); Px = accumarray(x, 1)/n; Hx = -dot(Px,log2(Px)); z = max(0,Hx); e...
ce2b0aa80023ae724aae1b7881709eb0e781289849856546cd0789b823159144
MATLAB
341
11
% See also span2index function index = range2index(range) %% If a vector is provided, assume that it's the first element of all ranges if isvector(range) range = range(:); range = [range(1:end-1), range(2:end)-1]; end index = arrayfun(@(x,y) x:y, range(:,1), range(:,2), 'UniformOutput...
314cb1e1e7852ad82ab6ea23ad9159290326efda417f83ad9ce1b2b9e76a8d97
MATLAB
342
15
classdef UtilImage % Image utilities methods (Static) function out = check_black_is_true(I) % check whether the black pixels are labeled as % "true" in the image format, since there should % be fewer black pixels out = sum(I(:)==true) < sum(I(:)==false); end ...
2302ff8606b630aafe5eb616b6c71b22e32a109db1ab6f471e5a5fbe3fc2a10e
MATLAB
343
15
%% % Recursively runs sum() on an input tensor, returning the sum over all given directions. function S = rsum(tensor, dim, varargin) if nargin < 2 || isempty(dim) S = sum(tensor(:)); else S = sum(tensor, dim(1), varargin{:}); for d = dim(2:end) S = sum(S, d, varargin{:}); ...
d1c8c02c3ca0d97888063d3ba07c37b01ab74a0a2b4550d4a89f4924e463faad
MATLAB
343
23
function listing = dir2(varargin) if nargin == 0 name = '.'; elseif nargin == 1 name = varargin{1}; else error('Too many input arguments.') end listing = dir(name); inds = []; k = 1; while k <= length(listing) if strcmp(listing(k).name(1), '.') inds(end + 1) = k; end k = k + 1; e...
67090bdbc7a4344faf3046b4beec1f67ce9f1d27291cc7a7c60ded5e1120d4c9
MATLAB
345
14
function draw_fixation(windowPtr, center, color) % Draws round fixation marker in the center of the window by superimposing % vertical and horizontal bars. % Written by KGS Lab % Edited by AS 8/2014 % find center of window center_x = center(1); center_y = center(2); Screen('DrawDots', windowPtr, [center_x center_y], ...
b45794424e8cfdd03f51a1c3a3ceab62ab4c5efe99c77ca07884abac1fa9c3a1
MATLAB
346
12
function [x] = create_design_matrix_model(EEG1) num_params = 4; % initialize with size (num events, number of parameters) x = zeros(length(EEG1),num_params); % categorical variables x(:,1) = [EEG1.AMs_i]; x(:,2) = [EEG1.NAMs_i]; % continous variables x(:,3) = nanzscore(log10(abs([EEG1.pks]))); % Intercept x(:,end) = ...
21c9c5d0f4a43bb40b916d358efb9c891a277d3880a0d1e84d72b345cc6d62f0
MATLAB
350
10
function [] = setup_miji() % @author: pdzialecka %% Add FIJI / MIJ paths % ADJUST these depending on local directories javaaddpath 'C:\Program Files\MATLAB\R2021a\java\jar\mij.jar' javaaddpath 'C:\Users\Pat\Desktop\Fiji.app\jars\ij-1.53q.jar' addpath(genpath('C:\Users\Pat\Desktop\Fij...
4545f2243618153dfb0be5cf936710787c5e4d94bcbceb6da1e63b0af7ff3ea6
MATLAB
351
13
%% Function to calculate Pearson's correlation and Fisher's z-score between two maps function [Pearsons, Fishers] = GetPearsons(mapI,mapII) [~,~,N_cell] = size(mapI); Pearsons= zeros(N_cell,1); Fishers = zeros(N_cell,1); for i = 1:N_cell Pearsons(i) = nancorr(mapI(:,:,i), mapII(:,:,i)); Fishers(i) = ...
d6d4fe07f1c2e2f8dd0c221fdc048f033875a03282f2d65887a79ea9d9cd40cf
MATLAB
352
7
function spacing = infer_electrode_spacing(positions) % INFER_ELECTRODE_SPACING Use the position coordinates to infer the average distance between electrodes % % 2010-06 phli - Abstracted out of plot_ei_.m % interpoint_distance_matrix = ipdm(positions, 'subset', 'nearest', 'result', 'struct'); spacing = median(inter...
35601103486b0f26760f23a27af5ff5b9f464edd339d99a02fb202390bd2cb3d
MATLAB
353
17
%% Writes lines into a text file function fid = writeFile(filePath, contents) fid = fopen(filePath, 'w'); if iscellstr(contents) for iLine = 1:numel(contents) fprintf(fid, '%s\n', contents{iLine}); end else fprintf(fid, '%s', contents); end if nargout < 1 ...
52adc119d1d0ac9b6e79ff60b84c5b9077807054724ea79c7cabee523916d0f4
MATLAB
354
21
%% % Even safer version of division, whereby x/0 is taken to be 0 no matter % what value x has. % function [z] = saferdiv(x, y, nil) z = zeros(size(y)); sel = (y ~= 0); if numel(x) > 1 z(sel) = x(sel) ./ y(sel); else z(sel) = x ./ y(sel); end if nargin > 2 ...
cb3a74ac1c8674a69322738fde9929b041bae122f2047f6c22b072842c1dd588
MATLAB
354
13
function C = convnPadded(A, B) % Applies replicate padding before convolution. Output is same size as A. padsize = (size(B)-1)/2; padsize_pre = floor(padsize); padsize_post = ceil(padsize); A_padded = padarray(A, padsize_pre, 'replicate', 'pre'); A_padded = padarray(A_padded, padsize_post, 'replicate', 'post'); C = ...
dd7902ae9c87ed96194a9da84effbf03938a4749a28e98d0e47010bb5ca0a7f0
MATLAB
354
14
function addaxis_zoom_pre(obj,evd) % update the added axes with new zoom % disp('zoom pre'); %======================================================== % Part of modification for ADDAXIS commands ystart = get(gca,'ylim'); %======================================================== setaddaxisdat...
c32c8d703a3ab3351713cb9ea31ee9594d534e4a1973a935aa7aca240faffedb
MATLAB
355
17
%% function [name] = range2str(minimum, maximum, separator, precision) if nargin < 3 separator = 'to'; end if nargin < 4 precision = 3; end if approx(minimum, maximum) name = num2str(minimum, precision); else name = [ num2str(minimum, precision) separator num2str(max...
58cb7187b776e8c32abb9d54822e79808098a9b8f58c3e50887ea5a6fcc6e883
MATLAB
356
15
function pfun=getSigmoidValue(X,sigmoid,m,width) % this gets the value of a given sigmoid with parameters: % 1: alpha % 2: beta % if isa(sigmoid,'function_handle') sigmoidHandle = sigmoid; elseif ischar(sigmoid) sigmoidHandle = getSigmoidHandle(sigmoid); else error('sigmoid of invalid type specified') en...
c4242cef3d44b8cb74ec136bddd3a210421bb497fd84799c868db4f20e5b08b4
MATLAB
356
17
%% function [output, status] = explorer(varargin) args = [varargin{:}]; if ~exist(args, 'file') try args = eval(args); end end if exist(args, 'dir') [status, output] = system(['explorer "' args '"']); else [status, output] = system(['explorer /s...
d1bebdfccc3f85af60d879228bd80a4a7044b848063ac887a1b14fad703cfd00
MATLAB
357
14
function str = titleCase(str) if iscell(str) for iStr = 1:numel(str) % str{iStr}(1) = upper(str{iStr}(1)); str{iStr} = regexprep(str{iStr}, '(^|\s+)(.)', '$1${upper($2)}'); end elseif ~isempty(str) % str(1) = upper(str(1)); str = regexprep(str, '(^|\s+)(.)...
e767eebcc91b6aa081ceac1995ef797cd3965e1aea87ff17c02b6b005991ccdf
MATLAB
359
15
% NANOUT Replace with NaN the entries of X corresponding to veto = true. % % Created : 25-Jun-2018 21:15:03 % Author : Sue Ann Koay (koay@princeton.edu) % function X = nanout(X, veto, flagValue) if nargin < 3 || isempty(flagValue) flagValue = nan; end assert(isequal(size(X), size(veto)));...
05bae163ce40a32353683a5810cf144cc7694a9f0597c5dffb6608e3a7d1eb9c
MATLAB
363
13
function [yes] = ishandletype(x, type) % ISHANDLETYPE Returns true if the given item(s) are graphics handles of % the desired type. yes = false(size(x)); for iX = 1:numel(x) yes(iX) = ishghandle(x(iX)) ... && any(strcmpi(get(x(iX), 'type'), typ...
51a2d8fa54da4a2efd38bffae8930d10674517186e26d656ce73eea78246c3a6
MATLAB
363
15
function config = read_config_file(socket) filename = read(socket, 1024, 'int8'); filename = filename(filename ~= 0); filename = char(filename'); warning( ... "gadgetron:external:config_filename", ... "[Unsupported] Client referenced config file by name: %s", ... filename ....
57b9de40d6e2152d80680b4a15047bf012e21209d38a879fe0fa885cbaa629ec
MATLAB
363
14
%% function to calculate events for splitted dataset function EventTime = GetEventTime(CaMatrix,frames) %% get splitted events [N_cell, ~] = size(CaMatrix); EventTime = cell(N_cell,1); for i = 1:N_cell QueryEvents = intersect(find(CaMatrix(i,:)==1),frames); % activity in query frames EventTime{i} = Q...
83dcafb4d44516ff90b93b540e8ed52212dd7fd1cac875d8e5346e62c40b6784
MATLAB
364
12
%% Return a struct that has only fields of the input that match the given regular expression pattern function K = keepfield(S, pattern, varargin) K = repmat(struct(), size(S)); keep = fieldsmatching(S, pattern, varargin{:}); for what = keep' for iObj = 1:numel(K) K(iObj).(what{:}) = S...
25783ff4cc2ca5b4a3b845269357fd9a944cf3986c251446e45c19b67dcad4dc
MATLAB
365
17
function [C,IA,IC,N] = nt_unique(A, varargin) %[C,IA,IC,N] = nt_unique(A, varargin) - unique with counts % % N: number of occurrences % % See unique for definition of other variables. % % NoiseTools [Asorted,iSort]=sortrows(A); [~,iReverse]=sort(iSort); [C,IA,IC]=unique(Asorted,varargin{:}); p=find([1;diff(IC);1]); ...
0a2ad7985dcefb3f38343dc985b611429ee9cfb3dc31f1b0e39d8450ddcc06eb
MATLAB
366
13
%% BINOFITF Calls binofit() when provided a fraction and a total count. function [phat, pci] = binofitf(fraction, total, varargin) count = fraction .* total; nearest = round(count); if all(istiny(count - nearest)) count = nearest; % else % keyboard end [phat, pci] ...
4b093f28ffd113fd593a96921b7749abc3c8bbd35331a92a1449183988248b82
MATLAB
368
20
function [R,M,k,D] = circ(a1,a2,a3) D = cross(a2-a1,a3-a1); b = norm(a1-a3); c = norm(a1-a2); if nargout == 1 a = norm(a2-a3); R = a*b*c/2/norm(D); return end E = cross(D,a2-a1); F = cross(D,a3-a1); G = (b^2*E-c^2*F)/norm(D)^2/2; M = a1 + G; R = norm(G); if R == 0 ...
c8a13552b3fc9beeafe302f3e5bc637e8658cd4dc66bb455748502813ea0e2b9
MATLAB
368
9
function D2 = naneucdist(XI,XJ) %NANEUCDIST Euclidean distance ignoring coordinates with NaNs n = size(XI,2); sqdx = (XI-XJ).^2; nstar = sum(~isnan(sqdx),2); % Number of pairs that do not contain NaNs nstar(nstar == 0) = NaN; % To return NaN if all pairs include NaNs D2squared = nansum(sqdx,2).*n./nstar; % Correctio...