//Example macro that does a diffusion analysis on a results table of tracking data
//The required format is as generated by the Manual Tracking plugin 
//assuming Results Table column headings; Track > Slice > X > Y
//It requires many tracks and many time points!
//Plots the cumulative mean squared displacement (MSD) per time point
//For a more accurate approach see the time ensemble average example

dis2 = 0;
for (i=0; i<nResults(); i++){
	if (getResult("Slice", i)==1) {setResult("Dis^2", i, 0);}

	else{ if (getResult("Track", i)>getResult("Track", i-1)) {setResult("Dis^2", i, 0);} 
	else {
	B9 = getResult("X", i);
	B8 = getResult("X", i-1);
	C9 = getResult("Y", i);
	C8 = getResult("Y", i-1);
	dis2 = (disx+disy);
	setResult("Dis^2", i, dis2);

//get last slice
maxslice = 0;
for (b=0; b<nResults(); b++) {
    if (getResult("Slice",b)>maxslice)
     maxslice = getResult("Slice",b);

//get first slice
minslice = maxslice;
for (c=0; c<nResults(); c++) {
    if (getResult("Slice",c)<minslice)
     minslice = getResult("Slice",c);

//Calculate MSD for each slice and append to a new array (MSD)
MSD = newArray();
time = newArray();
z = 0;

for (m=minslice; m<maxslice; m++){
	slice = newArray();
	for (l=0; l<nResults(); l++) {if (getResult("Slice", l)==m) {	
		x = getResult("Dis^2", l);
		slice = Array.concat(slice, x);
Array.getStatistics(slice, min, max, mean, std);
z = mean+z;
MSD = Array.concat(MSD, z);
time = Array.concat(time, t);
//Plot cumulative MSD against time
Fit.doFit("Straight Line", time, MSD);

//Richard Mort 26/01/2013
macro/basic_diffusion_analysis.txt · Last modified: 2013/01/26 09:58 by richardm
Back to top
CC Attribution-Noncommercial-Share Alike 3.0 Unported
chimeric.de = chi`s home Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0