help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: PCA with Octave


From: Israel Herraiz
Subject: Re: PCA with Octave
Date: Sat, 06 Jul 2013 11:50:40 +0200
User-agent: Sup/git

Excerpts from Mahmood Naderan's message of Sat Jul 06 10:19:04 +0200 2013:
> Hi
> I want to do a PCA (principal component analysis) with Octave. According to 
> what is stated here 
> http://osdir.com/ml/gnu.octave.general/2004-05/msg00038.html Here is what I 
> did
> 
> octave:1> X = transpose(dlmread("data.txt"));
> octave:2> size(X)
> ans =
> 
>      1   198
> 
> octave:3> C = cov(X)
> C =  37.531
> octave:4> [v, D] = eig(C)
> v =  1
> D =  37.531
> octave:5> PC1 = X*v[:,198];
> parse error:
> 
>   syntax error
> 
> >>> PC1 = X*v[:,198];

What are you trying to do with that line? If you are trying to index a
column of a matrix, you should use "(" and ")" instead of "[" and
"]". Using "[" to index is a syntax error ("[" is used to start
vectors and matrices).

But note that in your case X is just a vector, and so C is scalar (the
covariance of sample X). Therefore v is scalar, not a matrix, you
cannot index scalars (nor do a PCA over just a scalar, you need a
sample with several variables).

Cheers,
Israel


reply via email to

[Prev in Thread] Current Thread [Next in Thread]