PCA to reduce dimensionality to 99% variance
If what you want is PC compression, a more useful form of PCA would be achieved via Singular Value Decomposition (which is, in many cases, more accurate and faster than an eigendecomposition).

Assuming that X is a "tall" matrix with dimensions [n, p], n>p;
Then:

 [U, S, V] = svd(X);

eig_vals = diag(S.^2); %recall that eigenvalues of cov(X) are the singular values of X, squared.
percentages = cumsum(eig_vals)./sum(eig_vals); % cumulative variance. 

% Find the 99% variance
PC99 = find(percentages &gt;= 0.99, 1);

X_reduced = U(:,PC99)*S(PC99,PC99)*V(PC99,PC99)'; % compressed version of X


If X is a wide matrix [n &lt; p], you have to adjust the above expression a bit (all of V will be used, but only part of U, unlike here where V is truncated as well). We leave it as an exercise to the interested reader!

I will leave wiser people to comment on the judiciousness of PCA for compression. In many cases there are much more efficient schemes, such as wavelet decomposition followed by "thresholding" (zeroing out the coefficients  that fall below a certain threshold). But since your question assumes that you know what you want, so does the answer.