Borrar filtros
Borrar filtros

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

3 visualizaciones (últimos 30 días)
Adam el 25 de En. de 2023
Respondida: KSSV el 25 de En. de 2023
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);
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.

Respuestas (1)

KSSV el 25 de En. de 2023
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);


Más información sobre Dimensionality Reduction and Feature Extraction en Help Center y File Exchange.


Community Treasure Hunt

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

Start Hunting!

Translated by