bic ton
bic ton

Reputation: 1408

how to separate matrices in an array?

I want to apply a function for each four matrices, for example start from 1:4 then 5:8 then 9:12 ;13:16,17:20,21:24 and so on in my real data

 k = 24; n=3; m = 4
 ary=array(1:24, c(n,m,k))

 str(ary)
 int [1:3, 1:4, 1:24] 1 2 3 4 5 6 7 8 9 10 ...
 for each four matrices in ary fun {.........}

Upvotes: 0

Views: 43

Answers (1)

Phann
Phann

Reputation: 1327

If you want to use a for-loop as suggested in the question, just do the following:

Seq <- seq(1, 24, 4)
for (i in Seq){
   ## i is 1, 5, 9, 13, 17, 21
   ary[ , , i:(i+3)] #get's you the array with just four matrices
   # do something ...
}

Upvotes: 1

Related Questions