shawnthunt

Archive for the ‘Uncategorized’ Category

Matlab : Sort all rows of a matrix by a certain column

In Uncategorized on 12 January, 2009 at 14:39 pm

From: http://kb.iu.edu/data/afrd.html

In Matlab, how can I sort all of the rows of a matrix according to one of the columns?

If you wish to sort all the rows of a matrix in Matlab according to one of the columns, the general syntax for the command to use is:

[OldRowNumber, NewRowNumber] = sort(OldMatrix(:,SortColumn)); NewMatrix = OldMatrix(NewRowNumber,:);

Suppose, for example, you would like to rearrange the example matrix below (Figure 1) according to the value of the third column, so that your results would be as shown in Figure 2:

Figure 1

A = [1 2 3 3 0 9 6 5 4]

Figure 2

B = [1 2 3 6 5 4 3 0 9]

You would use the following command:

[x, i] = sort(A(:,3)); B = A(i,:);

Matlab :: Get Clicks on an Image

In Uncategorized on 5 January, 2009 at 10:23 am

This was taken from: http://users.ox.ac.uk/~scro1300/mosaic.htm

function

[X, Y] = ginput2(n)

X = []; Y = [];

fori=1:n

[px py ] = ginput(1);

X = [X ; px];

Y = [Y ; py];

plot( px, py, ‘r+’);

text_handle = text( px+5, py, num2str(i) );

set(text_handle,‘Color’,[0 1 0])

end

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

Visual Studio 2008 Error on GetPrivateProfileStringW

In Uncategorized on 23 September, 2008 at 09:20 am

error C2664: ‘GetPrivateProfileStringW’ : cannot convert parameter 1 from ‘const char *’ to ‘LPCWSTR’

Under Property Settings | General, set the Character set to “Use Multi-Byte Character Set”

Firefox losing settings

In Uncategorized on 13 September, 2008 at 19:56 pm

This has happened twice on me now, both time in Ubuntu 8.04.  The thing that ended up working was to delete the .mozilla folder in my home directory, remove Firefox, and install it again.

Installing R-project on Ubuntu

In linux on 5 September, 2008 at 13:14 pm

I thought I would get the R software loaded for a bioinformatics class I am taking this semester on my Ubuntu machine.  Here are the packages that were needed before I could compile it:

sudo apt-get install build-essential

sudo apt-get install gfortran

sudo apt-get install libreadline5-dev

sudo apt-get install xorg-dev

./configure

make

sudo make install