Skip to content

Instantly share code, notes, and snippets.

View kouichi-c-nakamura's full-sized avatar

Kouichi C. Nakamura kouichi-c-nakamura

View GitHub Profile
@kouichi-c-nakamura
kouichi-c-nakamura / forInteractiveUse
Created April 21, 2015 22:55
forInteractiveUse for matlab.unittest.TestCase
clear all;close all;clc;
testCase = Test; % Test is matlab.unittest.TestCase subclass
testCase.forInteractiveUse;
@kouichi-c-nakamura
kouichi-c-nakamura / spike2.plist
Last active August 29, 2015 14:23
a .plist file that enables syntax coloring of CED Spike2 scripts (.s2s files) in BBEdit and TextWrangler on Mac OSX! Not yet perfect, but does a good job. Useful, if you want to edit a script on your Mac. Save the spike2.plist in /Users/username/Library/Application Support/TextWrangler/Language Modules/. For general instructions, see http://www.…
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<!--
Spike2 language module for BBEdit
Kouichi C. Nakamura, PhD, Kyoto University
16 June 2015
kouichi.c.nakamrua@gmail.com
Based on
@kouichi-c-nakamura
kouichi-c-nakamura / exportEPSwithSpecifiedAxesSize.m
Last active October 30, 2015 13:30
MATLAB: to save a MATLAB figure into a color EPS with the specified size of the axes.
left = 2;
bottom = 2;
width = 8;
height = 11;
set(gca, 'Units', 'centimeters', 'Position', [left, bottom, width, height]);
print('filename1.eps','-depsc') % save as color EPS
@kouichi-c-nakamura
kouichi-c-nakamura / sortAasB.m
Last active October 30, 2015 13:31
MATLAB: To sort B in the same order as A (A and B have the same elements but not in the same order)
%% To sort A in the same order as B (A and B have the same elements but not in the same order)
A = [5 4 1 2 3 6];
B = [1 2 4 5 3 6];
[~, sort1] = sort(B);
[~, rev1] = sort(sort1);
[~, sort2] = sort(A);
C = A(sort2(rev1))
@kouichi-c-nakamura
kouichi-c-nakamura / Toggle_AppleShowAllFiles.sh
Last active October 30, 2015 13:34
Mac OS X: Toggle_AppleShowAllFiles
S1=`defaults read com.apple.finder AppleShowAllFiles`
C1='defaults write com.apple.finder AppleShowAllFiles -boolean'
# spaces within brackets are important
if [[ $S1 == '1' ]]; then
$C1 false
elif [[ $S1 == '0' ]]; then
$C1 true
else
# does not exist
@kouichi-c-nakamura
kouichi-c-nakamura / iscolorspec.m
Last active October 30, 2015 13:34
iscolorspec (MATLAB)
function TF = iscolorspec(colorSpec)
% TF = iscolorspec(colorSpec)
%
% Return true if coloarSpec is a valid coloarSpec
%
% http://mathworks.com/help/releases/R2014a/matlab/ref/colorspec.html
TF = ~isempty(colorSpec) && isrow(colorSpec) ...
&& isnumeric(colorSpec) ...
&& length(colorSpec) == 3 && all(colorSpec >= 0 & colorSpec <= 1) ...
@kouichi-c-nakamura
kouichi-c-nakamura / param_value_pair.m
Last active October 30, 2015 13:36
Add parameter and value pairs in input argument list of a function. It is strongly recommended to use InputParser class with addRequired, addOptional and addParameter methods.
funtion out1 = func1(arg1, arg2, varargin)
% function out1 = func1(arg1, arg2)
% function out1 = func1(_____, 'param1', value)
% function out1 = func1(_____, 'param2', value)
ni = length(varargin); % ni >= 1
DataInputs = 0;
PNVStart = 0; % index of the first parameter in varargin
@kouichi-c-nakamura
kouichi-c-nakamura / prealloc_nonscalar_struct.m
Last active October 30, 2015 13:36
Preallocation of non-scalar structure
c = cell([m n])
s = struct('field1', c,...
'field2', c,...
'field3', c)
for i=1:m
for j=1:n
s(m,n).field1 = 123;
s(m,n).field2 = 234;
s(m,n).field3 = 567;
@kouichi-c-nakamura
kouichi-c-nakamura / surf2eps.m
Last active November 9, 2015 07:17
surf plot can be benefitted from shading interp compared to images, but it is bloody hard to nicely export to Illustrator or ACD Canvas without loosing quality. Here is a workaround.
%% Hide surface objects and export in EPS with painter.
surfobjs = findobj(gcf,'Type','Surface');
set(surfobjs,'Visible','off');
% This allows you to save the figure except surface objects with painter renderer.
% 1 .Export Setup ... > Properties > Rendering > Custom Renderer > painters (vector format)
% 2. Export > neuronA_body.eps
print('-r600','-painters','depsc','neuronA_body.eps')
@kouichi-c-nakamura
kouichi-c-nakamura / shadedErrorBar_snippet.m
Last active November 9, 2015 07:30
A snippet for shaded error bar in MATLAB
X % row vector for X axis
themean % row vector for mean value
theerror % row vector for STD or SEM
% X, themean, and theerror must have the same length.
colorspec = 'g';
figure;
hold on;