On Wed, 22 Jun 2011 04:05:14 -0700 (PDT), Lavanya
<lavanya3k@gmail.com> wrote:
> Hi,
>
> I am trying to create a column vector of the form
>
> E = [[ 1, 1, 1, ......1], [e1,e2, .... ep], ......[e1(n),
> e2(n)....ep(n)]]
>
> where the first row values are one, p user input values. Now i need to
> fill the matrix with random values that are obtained from an PC
> image.
>
> Here is the code for reference:
>
> covMatrix = Correlate(image11, /COVARIANCE, /DOUBLE)
> eigenvalues = EIGENQL(covMatrix, EIGENVECTORS=eigenvectors, /DOUBLE)
> Print, eigenvalues
> Print, 'First Component (%): ', eigenvalues[0]/Total(eigenvalues)*100
>
> for i=0, bands-1 do begin;
> pc = eigenvectors ## Transpose(image11)
> pc1[*,*,i] = Reform(pc[*,i], rows, cols)
> ; pc1[*,*,i] = Reform(temporary(pc[*,i]), dims[0], dims[1],4)
> endfor
>
> p = 30
>
> TestMatrix = fltarr(p,p)
> TestMatrix(*,0) = 1
> idx1 = fltarr(1,p)
> ;data = pc(*,p-1)
>
> for i=0,p-1 do begin
> seed = 100L
> idx = floor(randomu(seed,p)) + 1
> TestMatrix(1:p,*) = pc(idx,*) ; error at
> this place
> idx1(i) = idx;
> endfor
>
> Finally, i need to construct TestMatrix
Some comments:
1. Use square brackets for array subscripts.
2. Why are you calculating pc within the loop? Should pc1 be pc? Also
check the function MATRIX_MULTIPLY to avoid ## with TRANSPOSE.
> for i=0, bands-1 do begin;
> pc = eigenvectors ## Transpose(image11)
> pc1[*,*,i] = Reform(pc[*,i], rows, cols)
> endfor
3. The reason why this fails is because TestMatrix has p columns, so
subscripting [1:p,*] won't work.
> TestMatrix(1:p,*) = pc(idx,*) ; error at this place
4. Define the seed outside the loop, otherwise you always get the same
"random" numbers.
5. To encourage people to answer your question, give a "minimal
working example" that we just have to copy&run. Filling in the gaps is
just too enjoying. Problems are often solved just by making a MWE.
|