the most straight forward way is just to get the top eigenvector/value of your data's covariance matrix using eigs
say the data matrix x
is N by D, or # of data by dimension of data
you can simply do
C = cov(X);
[V, D] = eigs(C, 1);
in fact, you can get the top k
principal components by running
[V, D] = eigs(C, k);