reshape help doing PCA when all images contained in one .mat file

2 次查看(过去 30 天)
I'm having issues writing code to reshape vectors correctly
I have a .mat file with variable X ∈ R 3240×200. Each column denotes a face image of size 60 × 54. So 200 faces total. I'm trying to plot an Image of the sample mean face, Images of the first three principal eigenvectors of the covariance matrix, and Images of any random face.
I'm have this code
load('.mat', 'X')
I = reshape(X(:, 1), 64, 56);
u = mean(X, 2);
svd(X)
eigvecs = svd(X);
I = reshape(eigvecs(:, 1), 64, 56);
The last line gives me
Error using reshape
Number of elements must not change. Use [] as one of the size inputs
to automatically calculate the appropriate size for that dimension.
I can't find an example online wherein all the PCA images are in one singular .mat file. Need to find a way to properly code so the eigvecs are reshaped correctly and matlab will produce the images.
Thanks!

回答(1 个)

KSSV
KSSV 2023-1-25
Your X data is of size 3240X20, you cannot reshape its each column to size 64X56..because 64X56=3584~=3240. So you need to use your reshape dimensions wisely. Think of your data properly.
Or, are you expecting this?
load('.mat', 'X')
u = mean(X, 2);
[U,S,V] = svd(X);

类别

Help CenterFile Exchange 中查找有关 Dimensionality Reduction and Feature Extraction 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by