File Exchange

image thumbnail

Nipals algorithm for Principle Component Analysis

version 1.2 (1.79 KB) by

This function is written largely based on nipals function from R chemometrics package.

1 Download


View License

It was frustrating that Matlab did not has a robust nipals function so I wrote one for my project and share here.

Comments and Ratings (7)


Eirik (view profile)

It looks to be a bug on line 37 (pcvar = zeros(varCount,1);). Change to (pcvar = zeros(a,1);) to get the correct size of pcvar (number of elements in pcvar should be equal number of desired components).

Qiaonan Duan

That's weird. There is no recursion in this function. You can send your data and script to me:
I will check that for you.


This is the message I got:
???Maximum recursion limit of 750 reached. Use set(0,'RecursionLimit',N)
to change the limit. Be aware that exceeding your available stack space can
crash MATLAB and/or your computer.

Error in ==> nipals

Qiaonan Duan

Is it possible you run it as a script while it is a function. X is the input matrix.

X = rand(5);

See if it gives you some result.


This is the error.
??? Input argument "X" is undefined.

Error in ==> nipals at 33
[obsCount,varCount] = size(X);

Qiaonan Duan

Hi could you give me the error message?
Line 33 is [obsCount,varCount] = size(X);
I cannot see there is any error here.


Sir, it shows that there is an error in the line 33. Can you please correct it? thank you for providing this program.



Line 48 (6/10/2013): prec = thnew-th; --> prec = (thnew-th)'*(thnew-th);

MATLAB Release
MATLAB 8.1 (R2013a)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Win prizes and improve your MATLAB skills

Play today