Skip to content

Instantly share code, notes, and snippets.

View schluppeck's full-sized avatar

Denis Schluppeck schluppeck

View GitHub Profile
@schluppeck
schluppeck / myPlot3.m
Last active August 29, 2015 14:20
wrap plot3 to accept coordinate input in [N x 3] + example
% use anonymous function to wrap Matlab plot3. Pass on options as per plot3
myPlot3 = @(P,varargin) plot3(P(:,1), P(:,2), P(:,3), varargin{:});
% e.g. make a noisy spiral
t = transpose( linspace(0, 2.*pi, 100) );
X =[sin(2.*t), cos(2.*t)+rand(size(t)), t]
% plot
figure
myPlot3(X, '.-', 'color', 'r', 'linewidth', 2)
axis vis3d
@schluppeck
schluppeck / download_citations
Last active August 29, 2015 14:20
download pubmed citations into JSON file using unix cURL
#!/bin/bash
#
# downloading pubmed data into json files
#
# used curl --help and stackoverflow for inspiration. also check out the posts here:
# http://superuser.com/questions/149329/what-is-the-curl-command-line-syntax-to-do-a-post-request
# define some variables - change as appropriate
author="schluppeck-d"
# pubmed search cgi is located here
# pmid2bibtex.rb
# convert a PubMed PMID to BibTeX citation format
# updated version of http://chrisamiller.com/science/2010/12/13/using-bioruby-to-fetch-citations-from-pubmed/
# works as of 2015-03-18
require 'bio'
Bio::NCBI.default_email = "me@me.com" # required for EUtils
id = "18265351"
pm = Bio::PubMed::efetch(id) # array of MEDLINE-formatted string
@schluppeck
schluppeck / jneurosci.m
Last active August 29, 2015 14:22
fix some aspect of formatting for matlab plots according to J Neurosci guidelines
function [ fHandle ] = jneurosci(fHandle, colWidth)
%jneurosci - provide some defaults for figures to get to JNeurosci style
%
% usage: [ fHandle ] = jneurosci( fHandle )
% by: lpzds1
% date: May 28, 2015
%
% inputs: fHandle, colWidth [1, 1.5, 2]
% outputs: fHandle
%
@schluppeck
schluppeck / convertImagesInFolder
Last active August 29, 2015 14:22
example of how to loop over rendered_thresh images in FSL folder and convert to PNG images using SLICER
#!/bin/bash
#
# example of how to use a simple BASH loop w/ FSL to traverse
# directories and create summary images of rendered_thresh_zstat?.hdr
# in a nice way
# input 1 is folder name
if [[ ! -d $1 ]]; then
echo "(uhoh) directory $1 does not exist"
echo " usage:"
@schluppeck
schluppeck / spectrovis.m
Created June 10, 2015 09:51
stimulus code for Lin et al (2012) JCBFM paper
% spectrovis.m
%
% $Id: spectrovis.m 1022 2012-08-07 10:29:58Z svnuser $
% usage: spectrovis(varargin)
% by: denis schluppeck based on mglRetinotopy by justin gardner
% date: 2010-06-06
%
% purpose: Displays a retinotopy stimulus, there are many
% parameters you can set, you can set as many
% or as few as you like.
@schluppeck
schluppeck / convHullArea.m
Created August 6, 2015 10:54
calculate the area of a convex hull of pointcloud
% make random coordinates on [0..1]
xy = rand(50,2)
% plot them with scatter
figure, scatter(xy(:,1), xy(:,2))
% get convex hull of cloud + plot
k = convhull(xy(:,1), xy(:,2))
hold on
plot(xy(k,1), xy(k,2), 'r-')
@schluppeck
schluppeck / rmText.m
Created August 20, 2015 16:14
remove text objects from matlab figure, so can export more easily to high-res bitmap
function [ ] = rmText(f_)
%rmText - remove text objects from a figure
%
% usage: [ ] = rmText( f_ )
% by: lpzds1, Denis Schluppeck
% date: Aug 20, 2015
% inputs: f_
% outputs:
%
% purpose: matlab figure exporting is a bit of a pain, so sometime one
@schluppeck
schluppeck / printTermTime.sh
Created September 4, 2015 17:49
UNIX way of printing repeating dates
#! /bin/bash
#
# creating a table that contains a given term week (2,3,4...)
# and the corresponding dates. using bash / unix. e.g.
# Week 2 - Wed 30 Sep 2015
# Week 3 - Wed 7 Oct 2015
# Week 4 - Wed 14 Oct 2015
# Week 5 - Wed 21 Oct 2015
@schluppeck
schluppeck / HartigansDipTest.m
Created September 14, 2015 15:45
Matlab code of Hartigans Dip Test [FORTRAN], as implemented by Ferenc Mechler, 2002; and retrieved from http://nicprice.net/diptest/
function [dip,xl,xu, ifault, gcm, lcm, mn, mj] = HartigansDipTest(xpdf)
% function [dip,xl,xu, ifault, gcm, lcm, mn, mj]=HartigansDipTest(xpdf)
%
% This is a direct translation by F. Mechler (August 27 2002)
% into MATLAB from the original FORTRAN code of Hartigan's Subroutine DIPTST algorithm
% Ref: Algorithm AS 217 APPL. STATIST. (1985) Vol. 34. No.3 pg 322-325
%
% Appended by F. Mechler (September 2 2002) to deal with a perfectly unimodal input
% This check the original Hartigan algorithm omitted, which leads to an infinite cycle