How to get my desired dimension using pca in MATLAB?

2 vues (au cours des 30 derniers jours)
Sunil Kumar
Sunil Kumar le 29 Fév 2020
Réponse apportée : Aditya le 25 Mar 2025
My matrix is of dimension 101x64. After applying PCA the matrix got reduced to 64x64. I want my reduced matrix to be of form 1xN. How can i do this?
  1 commentaire
nathan welch
nathan welch le 6 Mar 2020
I don't think Principle Component Analysis (PCA) can reduce your matrix to a row vector.
If you're using it in a similar manner to Singular Value Decomposition (SVD) and factorizing your rectangular matrix into the form:
Then the information you problem want is the scalar data from the diagonal matrix
If you can get hold of this then you can extract the diagonal elements using: s = diag(Sigma)'
This should then give you a 1x64 set of values.

Connectez-vous pour commenter.

Réponses (1)

Aditya
Aditya le 25 Mar 2025
Hi Sunil,
To reduce your matrix to a form of (1 \times N) using PCA, you'll need to perform a few steps. Typically, PCA reduces the dimensionality by projecting the data onto a smaller number of principal components. Here's a general approach to achieve a (1 \times N) matrix:
% Assume X is your original 101x64 data matrix
X = rand(101, 64); % Example data
% Center the data
X_centered = X - mean(X);
% Compute the covariance matrix
covMatrix = cov(X_centered);
% Perform eigen decomposition
[eigenVectors, eigenValues] = eig(covMatrix);
% Sort eigenvectors by eigenvalues in descending order
[~, sortedIndices] = sort(diag(eigenValues), 'descend');
eigenVectors = eigenVectors(:, sortedIndices);
% Project the data onto the principal components
% Here, we project onto all 64 components (can be reduced as needed)
projectedData = X_centered * eigenVectors;
% Flatten the projected data to form a 1xN vector
% Here, N is 64*64 = 4096 for full projection
flattenedData = reshape(projectedData', 1, []);
% If you want fewer components, adjust the number of columns in eigenVectors
% For example, to keep only the first 10 components:
numComponents = 10;
projectedDataReduced = X_centered * eigenVectors(:, 1:numComponents);
flattenedDataReduced = reshape(projectedDataReduced', 1, []);

Catégories

En savoir plus sur Dimensionality Reduction and Feature Extraction dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by