From: Diana Gonzalez on
hi everyone,

I want to extract all the principal components of a 14209*2048 array, when I apply the princomp command it shows this error:
??? Error using ==> svd
Input to SVD must not contain NaN or Inf.
I don't know how to deal with it.....can somebody help me?

thanks...
From: Tom Lane on
> I want to extract all the principal components of a 14209*2048 array, when
> I apply the princomp command it shows this error:
> ??? Error using ==> svd
> Input to SVD must not contain NaN or Inf.
> I don't know how to deal with it.....can somebody help me?

It sounds like you have NaN or Inf in your array. If you have NaNs
representing missing values, one option is to remove rows with NaNs.

Another is somehow to estimate the covariance and call the pcacov function
instead of the princomp function. For example, it might be possible to
combine nanvar and corrcoef, the latter using the option to compute
'pairwise' correlations using as much data as possible for each pair.
There's a danger that the resulting matrix won't be positive definite (won't
be a valid covariance or correlation matrix), but it's something to try out.

-- Tom


From: Diana Gonzalez on
"Tom Lane" <tlane(a)mathworks.com> wrote in message <hneamj$2s8$1(a)fred.mathworks.com>...
> > I want to extract all the principal components of a 14209*2048 array, when
> > I apply the princomp command it shows this error:
> > ??? Error using ==> svd
> > Input to SVD must not contain NaN or Inf.
> > I don't know how to deal with it.....can somebody help me?
>
> It sounds like you have NaN or Inf in your array. If you have NaNs
> representing missing values, one option is to remove rows with NaNs.
>
> Another is somehow to estimate the covariance and call the pcacov function
> instead of the princomp function. For example, it might be possible to
> combine nanvar and corrcoef, the latter using the option to compute
> 'pairwise' correlations using as much data as possible for each pair.
> There's a danger that the resulting matrix won't be positive definite (won't
> be a valid covariance or correlation matrix), but it's something to try out.
>
> -- Tom
>
thanks for your help Tom. I followed your first option without success, I found on mathworks website that if I want to remove NaN elements from a matrix I should execute X(any(isnan(X)' ),:) = []; but it seems that it becomes the matrix x in an empty array because it shows that x is an empty matrix after that. do you know why it happens? and how could I just remove specific elements? because that code removes all the rows that contains NaN elements.

thanks for your help.

Diana