Skip to content

Instantly share code, notes, and snippets.

@janfreyberg
Last active March 3, 2017 14:05
Show Gist options
  • Save janfreyberg/193d38f4bd1aeca6980c6b9888674008 to your computer and use it in GitHub Desktop.
Save janfreyberg/193d38f4bd1aeca6980c6b9888674008 to your computer and use it in GitHub Desktop.
Ipython notebooks
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# This notebook uses the `matlab_kernel`.\n",
"\n",
"You can install this kernel from pypi by typing `pip install matlab_kernel`"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1\n",
"\n",
" 2\n",
"\n",
" 3\n",
"\n",
" 4\n",
"\n",
" 5\n",
"\n",
" 6\n",
"\n",
" 7\n",
"\n",
" 8\n",
"\n",
" 9\n",
"\n",
" 10\n",
"\n",
" 11\n",
"\n",
" 12\n",
"\n",
" 13\n",
"\n",
" 14\n",
"\n",
" 15\n",
"\n",
" 16\n",
"\n",
" 17\n",
"\n",
" 18\n",
"\n",
" 19\n",
"\n",
" 20\n"
]
}
],
"source": [
"% this is matlab code\n",
"for i = 1:20\n",
" disp(i)\n",
"end\n",
"test = 'teststring';"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"command line works too\n"
]
}
],
"source": [
"!echo \"command line works too\""
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%plot native\n",
"plot(1:500, 1:2:1000)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"this is a python string\n",
"0\n",
"1\n",
"2\n",
"3\n",
"4\n"
]
}
],
"source": [
"%%python\n",
"print('this is a python string')\n",
"for a in range(5):\n",
" print(a)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Let's try some rudimentary imaging analysis\n",
"\n",
"T1 from some random person:"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"!fslview /Users/jan/Documents/prf-data/freesurfer/subjects/starling44_2/mri/T1.nii"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"And we can do the same in matlab:"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"im = read_avw('/Users/jan/Documents/prf-data/freesurfer/subjects/starling44_2/mri/T1.nii');\n",
"imshow(im(:, :, round(end/2))/255)\n"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {
"collapsed": false
},
"outputs": [
{
"ename": "ImportError",
"evalue": "(\"No module named 'nipy'\",)",
"output_type": "error",
"traceback": [
" File \"/Library/anaconda/envs/py35/lib/python3.5/site-packages/metakernel/magics/python_magic.py\", line 19, in exec_code\n exec(code, env)\n",
" File \"<string>\", line 1, in <module>\n"
]
}
],
"source": [
"%%python\n",
"from nipy.interfaces.fsl import utils\n",
"smoother = Smooth()\n",
"viewer.inputs.in_file = '/Users/jan/Documents/prf-data/freesurfer/subjects/starling44_2/mri/T1.nii'\n",
"viewer.inputs.output_type = 'NIFTII_GZ'\n",
"viewer.run()"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%plot -s 500,500"
]
}
],
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Matlab",
"language": "matlab",
"name": "matlab"
},
"language_info": {
"codemirror_mode": "octave",
"file_extension": ".m",
"help_links": [
{
"text": "MetaKernel Magics",
"url": "https://github.com/calysto/metakernel/blob/master/metakernel/magics/README.md"
}
],
"mimetype": "text/x-octave",
"name": "matlab",
"version": "0.11.0"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment