Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8631805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:16:05+00:00 2026-06-12T09:16:05+00:00

Possible Duplicate: MATLAB is running out of memory but it should not be I

  • 0

Possible Duplicate:
MATLAB is running out of memory but it should not be

I want to perform PCA analysis on a huge data set of points. To be more specific, I have size(dataPoints) = [329150 132] where 328150 is the number of data points and 132 are the number of features.

I want to extract the eigenvectors and their corresponding eigenvalues so that I can perform PCA reconstruction.

However, when I am using the princomp function (i.e. [eigenVectors projectedData eigenValues] = princomp(dataPoints); I obtain the following error :

>> [eigenVectors projectedData eigenValues] = princomp(pointsData);
Error using svd
Out of memory. Type HELP MEMORY for your options.

Error in princomp (line 86)
[U,sigma,coeff] = svd(x0,econFlag); % put in 1/sqrt(n-1) later

However, if I am using a smaller data set, I have no problem.

How can I perform PCA on my whole dataset in Matlab? Have someone encountered this problem?

Edit:

I have modified the princomp function and tried to use svds instead of svd, but however, I am obtaining pretty much the same error. I have dropped the error bellow :

Error using horzcat
Out of memory. Type HELP MEMORY for your options.

Error in svds (line 65)
B = [sparse(m,m) A; A' sparse(n,n)];

Error in princomp (line 86)
[U,sigma,coeff] = svds(x0,econFlag); % put in 1/sqrt(n-1) later
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T09:16:05+00:00Added an answer on June 12, 2026 at 9:16 am

    Solution based on Eigen Decomposition

    You can first compute PCA on X'X as @david said. Specifically, see the script below:

    sz = [329150 132];
    X = rand(sz);
    
    [V D] = eig(X.' * X);
    

    Actually, V holds the right singular vectors, and it holds the principal vectors if you put your data vectors in rows. The eigenvalues, D, are the variances among each direction. The singular vectors, which are the standard deviations, are computed as the square root of the variances:

    S = sqrt(D);
    

    Then, the left singular vectors, U, are computed using the formula X = USV'. Note that U refers to the principal components if your data vectors are in columns.

    U = X*V*S^(-1);
    

    Let us reconstruct the original data matrix and see the L2 reconstruction error:

    X2 = U*S*V';
    L2ReconstructionError = norm(X(:)-X2(:))
    

    It is almost zero:

    L2ReconstructionError =
      6.5143e-012
    

    If your data vectors are in columns and you want to convert your data into eigenspace coefficients, you should do U.'*X.

    This code snippet takes around 3 seconds in my moderate 64-bit desktop.

    Solution based on Randomized PCA

    Alternatively, you can use a faster approximate method which is based on randomized PCA. Please see my answer in Cross Validated. You can directly compute fsvd and get U and V instead of using eig.

    You may employ randomized PCA if the data size is too big. But, I think the previous way is sufficient for the size you gave.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Growable data structure in MATLAB So in my current MATLAB script, I
Possible Duplicate: Automatically plot different colored lines in MATLAB I have the following data
Possible Duplicate: Why not use tables for layout in HTML? Under what conditions should
Possible Duplicate: How can I convert a list<> to a multi-dimensional array? I want
Possible Duplicate: How to do the vector of sets in C++? I want to
Possible Duplicate: check whether internet connection is available with C# I just want to
Possible Duplicate: Bayesian networks in MATLAB Is there a toolbox in Matlab which implement
Possible Duplicate: Binary representation of a number in Matlab I am using matlab and
Possible Duplicate: How do I do multiple assignment in MATLAB? When dealing with cell
Possible Duplicate: How do I do multiple assignment in MATLAB? So let's say I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.