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).

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.

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).

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

Comment only