loops to fill a matrix
Posted: Tue May 17, 2011 11:15 pm
Hi, I have another coding issue. I would like to fill a matrix using a for loop so that each cell in a column is equal to the value of the cell above it multiplied by (1 - the value of the cell above the corresponding cell in another matrix). Therefore, using microsoft excel to demonstrate, B2 = B1*(1-A1) and then dragging down. I've been using @subextract to extract just the one cell so it looks like this:
For !m=1 to @rows(x)
If !m>=2 then
x(!m)=(@subextract(x,!m-1,1,!m-1,1))*(@subextract(units,!m,1,!m,1)-(@subextract(y,!m-1,1,!m-1,1)))
endif
next
; where x is currently a vector and y is the other matrix (with the info) and units is a "ones" matrix. I figured I would nest this loop within another loop (if x was a nxn matrix instead) so that I can do the same procedure for every column. When I run the above code it tells me non-numeric argument in "x(2)=@subextract...."
Thanks heaps,
kuuks.
For !m=1 to @rows(x)
If !m>=2 then
x(!m)=(@subextract(x,!m-1,1,!m-1,1))*(@subextract(units,!m,1,!m,1)-(@subextract(y,!m-1,1,!m-1,1)))
endif
next
; where x is currently a vector and y is the other matrix (with the info) and units is a "ones" matrix. I figured I would nest this loop within another loop (if x was a nxn matrix instead) so that I can do the same procedure for every column. When I run the above code it tells me non-numeric argument in "x(2)=@subextract...."
Thanks heaps,
kuuks.