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

  • SEARCH
  • Home
  • 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 8963441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:21:22+00:00 2026-06-15T16:21:22+00:00

I am implementing a PCA algorithm in MATLAB. I see two different approaches to

  • 0

I am implementing a PCA algorithm in MATLAB. I see two different approaches to calculating the covariance matrix:

C = sampleMat.' * sampleMat ./ nSamples;

and

C = cov(data);

What is the difference between these two methods?

PS 1: When I use cov(data) is that unnecessary:

meanSample = mean(data,1);
data = data - repmat(data, nSamples, 1);

PS 2:

At first approach should I use nSamples or nSamples - 1?

  • 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-15T16:21:24+00:00Added an answer on June 15, 2026 at 4:21 pm

    In short: cov mainly just adds convenience to the bare formula.

    If you type

    edit cov
    

    You’ll see a lot of stuff, with these lines all the way at the bottom:

    xc = bsxfun(@minus,x,sum(x,1)/m);  % Remove mean    
    if flag
        xy = (xc' * xc) / m;
    else
        xy = (xc' * xc) / (m-1);  % DEFAULT 
    end
    

    which is essentially the same as your first line, save for the subtraction of the column-means.

    Read the wiki on sample covariances to see why there is a minus-one in the default path.

    Note however that your first line uses normal transpose (.'), whereas the cov-version uses conjugate-transpose ('). This will make the output of cov different in the context of complex-valued data.

    Also note that cov is a function call to a non-built in function. That means that there will be a (possibly severe) performance penalty when using cov in a loop; Matlab’s JIT compiler cannot accelerate non-built in functions.

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

Sidebar

Related Questions

I'm implementing PCA using eigenvalue decomposition for sparse data. I know matlab has PCA
When implementing a custom membership provider I see that the underlying data model has
Implementing the basic algorithm using last array as a pivot in Java, is it
When implementing a Matrix construct using arrays, which would be more efficient? Using a
Implementing equals() and hashCode() for simple data POJOs is cluttering my code and maintaining
After implementing matrix multiplication with CUDA. I tried to implement it with CUBLAS(thanks to
Implementing a datastructure with two function pointers, key_eq and key_hash . When these function
Im implementing a reminder app.There are two reminders (one for everyday and other for
implementing this on MATLAB for my project. I have a circle divided up to
After implementing the data structure suggested in this thread , I decided to fill

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.