Skip to content

Instantly share code, notes, and snippets.

@tonyfast
tonyfast / fromPlotly.m
Created July 22, 2014 22:25
Load Plotly graph information directly to Matlab
function data = fromPlotly( url )
%% Import data from Plotly graphs into the matlab workspace using urlread.
% With ``fromPlotly`` in your path, call fromPlotly(url) where ``url`` is a
% link to a valid Plotly plot.
%% Example URI
% url = 'https://plot.ly/~TonyFast/4'
%% Loading in data to Matlab from a plot.ly link
@tonyfast
tonyfast / driver.m
Last active August 29, 2015 14:04
Peak and Valley finding coarse for N-D Volumetric datasets for N>=1
%% Example use of peakfind
A = round( checkerboard( 10 ) );
[G] = peaks( 61 );
B = peakfind( G, 'neighborhood', [ 5 5] );
% B - Boolean matrix of peaks
[x,y] = find( B );
@tonyfast
tonyfast / partition_space.m
Last active August 29, 2015 14:04
Partition Portions of N-D Arrays in Matlab using either a center of a region or corner of a region as a reference.
function part = partition_space( Data,varargin );
% Remove subsets of information from large volumetric images
% Two options
% # ``corner`` <<default>> - Reference position is the top left corner of
% the image.
% ``window`` - is a vector where each element defines the window
% size in a given direction
% # ``center`` - the center of the iamge
% ``window`` - is a column vector where each row is the dimension
% of the array and the first a distance less than the center and
@tonyfast
tonyfast / trimnd.m
Created July 25, 2014 01:50
Trim zeros and nan's off of an N-D array in matlab
function trimmed = trimnd( trimmed )
% Trim an N-D matrix with extra zero columns.
% Delete zero slices for a more compact viz
for ii = 1 : 3
b = all( trimmed == 0 | isnan( trimmed ) ,ii);
for jj = setdiff( 1 : 3, ii )
deletecol = setdiff( 1 : 3, [ii,jj] );
b2 = all( b, jj );
for qq = 1 : 3; evalindex{qq} = ':';end
@tonyfast
tonyfast / liquid2js.html
Created July 30, 2014 04:35
Work Around to Using YAML Front Matter in Javascript
---
foo: bar
---
<div id="frontmatter" style-"display:none;">{{page['foo']}}</div>
<script>
// In Jquery
jsvar = $(".fields").text();
// In d3
@tonyfast
tonyfast / matlab_syntax.md
Last active August 29, 2015 14:04
Commenting Nested Lines of Code in Matlab

Matlab

Love it (I do!) or hate it (You're using it for the wrong thing); Matlab is a numerical computing engine. Similarly, Matlab is an incredible medium to learn how to numerically program. Their documentation is fantastic because it is not only filled with syntax, but theory and equations. I think it is possible to learn a lot while learning Matlab. Matlab is the Kool-Aid man equivalent of numerical computing; it can smash through most walls and make an enormous mess doing it. OH YEA!

This document discusses one of the ideas I use to write better documentation for vectorized Matlab code.

Publishing Matlab Code

Matlab has a publish function that uses formatted comments and a few special functions to provide several presentation layers on executed code (e.g. PDF, HTML). This is all well and good, but for vectorized matlab code it just doesn't matter.

@tonyfast
tonyfast / paginate.html
Last active August 29, 2015 14:05
Easy solution to Jekyll /page1 when paginating
<!--
See http://jekyllrb.com/docs/pagination/#render-the-paginated-posts
for futher usage of pagination on Jekyll pages
-->
<div class="pagination">
{% if paginator.previous_page %}
<a href="{{ paginator.previous_page_path }}" class="previous">Previous</a>
{% else %}
<span class="previous">Previous</span>
@tonyfast
tonyfast / cmd
Created August 18, 2014 15:02
Exposing All Files in Git history
git log --pretty=format: --name-only --diff-filter=A | sort -u
@tonyfast
tonyfast / project.md
Created August 23, 2014 04:43
Class Project Description Outline

Insert Title Here

Team Members

  • Person One - Home Department
  • Person Two - Home Department

Abstract

@tonyfast
tonyfast / flickr_hack_photo.m
Created August 28, 2014 20:27
A Matlab code to hack Flickr for sharing uniformly gridded, non-image data.
%% Flickr Translation Function
% This code requires:
% JSON Lab: http://www.mathworks.com/matlabcentral/fileexchange/33381-jsonlab--a-toolbox-to-encode-decode-json-files-in-matlab-octave
%% Load Example Image
% This example image was provided Dr. Mark Stoudt at NIST. It is surface
% roughness data for High Purity Aluminum. The experiment's detector
% measures the height of aberations on the surface of rolled sheet
% aluminum. The data has postive and negative float values. In the title
% of the Flickr image I have added arguments for scaling and translating