shawnthunt

Archive for December, 2008

Matlab Block Comments

In Uncategorized on 23 December, 2008 at 09:40 am

Use the tags “%{” and “%}”, e.g.:

%{

projective transformation notes:

[up vp wp] = [x y w] * tInv
u = up / wp
v = vp / wp

tInv = [ A D G
B E H
C F I]

u = (Ax + By + C) / (Gx + Hy + 1)
v = (Dx + Ey + F) / (Gx + Hy + 1)

%}

Correlation Coefficient (Pearson)

In Uncategorized on 4 December, 2008 at 20:51 pm

Here is a C++ function to find the correlation coefficient of two matrices:

float corr(float *x, float *y, int n)
{
float ax=0.0, ay=0.0;
float xt=0.0, yt=0.0;
float sxx=0.0, syy=0.0, sxy=0.0;

// find the means first
for (int i=0; i<n; i++) {
ax += x[i];
ay += y[i];
}

ax /= n;
ay /= n;

// compute the correlation coeffcient
for (int i=0; i<n; i++) {
xt = x[i]-ax;
yt = y[i]-ay;
sxx += xt*xt;
syy += yt*yt;
sxy += xt*yt;
}

return sxy/sqrt(sxx*syy);

} // end corr