r,matrix,replace,assign,submatrix

You can take advantage of having equal rownames and colnames in all matrices and just subset the big matrix according to the submatrix, and then replace the values: X <- read.table(text=" AB-2000 AB-2600 AB-3500 AC-0100 AD-0100 AF-0200 AB-2000 6.5 NA -1.8 3.65 -17.96 -26.5 AB-2600 NA 7.18 NA NA NA...

arrays,matlab,vectorization,reshape,submatrix

You could do - [m,n,r] = size(A); X = P*reshape(A(:,:,1),m*n,[]) If you are doing it iteratively along the third dimension of A, i.e. for A(:, :, iter), where iter is the iterator, you could get all X's in a vectorized manner in an array like so - X_all = P*reshape(A,m*n,[])...

You could do this using simple linear indexing. The following code is self-explanatory. matrixRows=9; matrixCols=9; blockRows=3; blockCols=3; accessRow=2; accessCol=3; A = randi(10,[matrixRows,matrixCols])-1; allPos=allcomb(accessRow:blockRows:matrixRows,accessCol:blockCols:matrixCols); linPos=sub2ind(size(A),allPos(:,1),allPos(:,2)); % access them as usual and put any value A(linPos)=-100; Result: A = 8 9 7 3 6 4 1 6 8 9 1 9 6...

Sadly as GSL does it's LU decompositions in place I'm not sure that it's possible to do it without copying the submatrix out of A first if you require it not to be modifed. You can, however, use a matrix view to construct the inverse directly from the LU decomposition...

My guess is that you have to compute how many submatrices of M have sum equal to 36. Here is Matlab code: a=[1,2,3,2,5]; n=length(a); M=a'*a; count = 0; for a0 = 1:n for b0 = 1:n for a1 = a0:n for b1 = b0:n A = M(a0:a1,b0:b1); if (sum(A(:))==36) count...

arrays,matlab,matrix,multidimensional-array,submatrix

For the initial case (4x4 into 2x2x2x2x2) use M= permute(reshape(X',[2,2,2,2]),[4,2,3,1]); For a general case where size(X) = a x b) and size(M) = c x d x e x f such that a*b = c*d*e*f, for any natural number n, use M= permute(reshape(X',[c,d,e,f]),[4,2,3,1]); ...

One other approach with bsxfun, reshape and permute function [ out ] = quadrants( n ) out = reshape(permute(reshape(bsxfun(@times,... ones(n,n,4),permute(1:4,[1 3 2])),n,2*n,[]),[1 3 2]),2*n,[]); end Results: >> quadrants(3) ans = 1 1 1 2 2 2 1 1 1 2 2 2 1 1 1 2 2 2 3 3...

Here is a solution in m-code: %your input M=rand(10,10,10); S=[2,3,4] %generate indices: Index=arrayfun(@(x)(1:x),S,'uni',0) %use comma separated list to index: smallM=M(Index{:}) ...

Perhaps a strategy like this could work submat <- function(m, nrow, ncol) { stopifnot(nrow(m)>=nrow, ncol(m)>=ncol) rowstarts<-1:(nrow(m)-nrow+1) colstarts<-1:(ncol(m)-ncol+1) ss <- function(r, c) { m[r:(r+nrow-1), c:(c+ncol-1), drop=FALSE] } with(expand.grid(r=rowstarts, c=colstarts), mapply(ss, r, c, SIMPLIFY=FALSE)) } submat(M, 4, 4) we determine where the possible start indexes for the rows and columns are, then...

Try this: n = 26; result = reshape(sum(reshape(x.', n, []), 1), [], size(x, 1)).'; You can look at intermediate results to see how this works: reshape(x.', n, []), then sum(reshape(x.', n, []), 1) etc...