Questions tagged [submatrix]

A submatrix is a matrix formed by selecting a subset of the rows and columns of one larger matrix. Questions tagged [submatrix] deal with implementation issues regading accessing the relevant rows/columns of the larger matrix, relevant memory issues, etc.

A submatrix is a matrix formed by selecting a subset of the rows and columns of one larger matrix.

For example, let A be a matrix of size n-by-m

A = [ a00 a01 ...
      a10 a11 ...
      .       .
      .        .
      .         .
      an1 an2 ... anm ]

Then one can form a 2-by-3 sub-matrix by selecting rows 2 and 5, and columns 1,4 and 6.
The resulting sub-matrix is then

S = [ a21 a24 a26
      a51 a54 a56 ]

Questions tagged [submatrix] deal with implementation issues regading accessing the relevant rows/columns of the larger matrix, relevant memory issues, etc.

183 questions
3
votes
1 answer

Manipulating sub matrices in R

Nh<-matrix(c(17,26,30,17,23, 17 ,24, 23), nrow=2, ncol=4); Nh Sh<-matrix(c(8.290133, 6.241174, 6.096808, 7.4449672, 6.894924, 7.692115, 4.540521, 7.409122), nrow=2, ncol=4); Sh NhSh<-as.matrix(Nh*Sh); NhSh rh<-c( 0.70710678,…
Sam
  • 95
  • 10
3
votes
1 answer

C - Split matrix into equipartitions

I'm writing an algorithm to divide a matrix into 4 submatrices(equipartitions). Size of the whole matrix is always multiplier of 4 as being shown in the added image. If you watch out, I'm trying to access elements like 1D element instead of 2D. I…
3
votes
1 answer

Maximum subarray of size HxW within a 2D matrix

Given a 2-dimensional array of positive integers, find the subrectangle of size HxW with the largest sum. The sum of a rectangle is the sum of all the elements in that rectangle. Input: A 2D array NxN with positive elements The HxW size of the…
drakerc
  • 139
  • 8
3
votes
3 answers

How to print all square submatrices of square matrix in C?

Please, help me to find and print all square submatrices of square matrix from big to small square matrices in C programming language I wrote code that works wrong: int main() { int mtrx_size = 8; int mat[8][8] = { { 1, 2, 3, 4, 5,…
ata.niazov
  • 43
  • 1
  • 1
  • 4
3
votes
2 answers

Finding a submatrix with the maximum possible sum in O(n^2)

I'm trying to write a program in Java that when given an MxN matrix it will find the (contiguous) submatrix with the biggest sum of numbers. The program then needs to return the top left corner coordinates of the submatrix and the bottom right…
Meir
  • 12,285
  • 19
  • 58
  • 70
3
votes
3 answers

Matlab: select submatrix from matrix by certain criteria

I have a matrix A A=[f magic(10)] A= 931142103 92 99 1 8 15 67 74 51 58 40 931142103 98 80 7 14 16 …
3
votes
1 answer

Split matrix into submatrices

I found a solution to a similar question that breaks up a matrix into a set of non-overlapping sub-matrices when the matrix may not be square (as it may not be in my situation) Function to split a matrix into sub-matrices in R. However, in my case…
Beaker
  • 2,804
  • 5
  • 33
  • 54
3
votes
0 answers

Identify every submatrix satisfying condition

In the following matrix I'm trying to identify every largest rectangles formed by 1's as shown in the picture. Rectangles can have just one row only if they have more than 3 columns. Rectangles can have just one column only if they have more than…
user3437823
  • 351
  • 2
  • 14
3
votes
4 answers

Numpy submatrix operations

I'm looking for an efficient way to perform submatrix operations over a larger matrix without resorting to for loops. I'm currently doing the operation (for a 3x3 window): newMatrix = numpy.zeros([numRows, numCols]) for i in range(1, numRows-1): …
James Jenkinson
  • 1,563
  • 2
  • 16
  • 33
3
votes
2 answers

MATLAB - matrix multiply submatrices within a single matrix

I am trying to multiply the (2x2) sub-matrices of a large (2x2m) matrix together, in a "vectorized" fashion in order to eliminate for loops and increase speed. Currently, I reshape to a (2x2xm) then use a for loop to do this: for n = 1:1e5 m =…
JoeN
  • 51
  • 6
2
votes
4 answers

Finding sub matrix of a given matrix

i am trying to write an algorithm for finding a sub matrix in a given sub matrix. To solve this problem i had written the following code: public class SubMatTry { /** * @param args */ public static void main(String[] args) { // TODO…
Ashwani Kumar
  • 834
  • 3
  • 16
  • 30
2
votes
2 answers

Sampling submatrices in R

Given a matrix like mat > set.seed(1) > mat <- matrix(rbinom(100,1,0.5),10,10) > rownames(mat) <- paste0(sample(LETTERS[1:2],10,replace=T),c(1:nrow(mat))) > colnames(mat) <- paste0(sample(LETTERS[1:2],10,replace=T),c(1:ncol(mat))) > mat A1 A2 A3…
Zachary
  • 345
  • 1
  • 8
2
votes
2 answers

Extract submatrix from matrix

I create a matrix in R with 10x10 (10 rows and 10 columns): matriz <- matrix(1:100, nrow = 10, ncol = 10, byrow=T) I want to extract square submatrices (3x3) from matrix (matriz), randomly and without overlap. I see a package in R named…
2
votes
1 answer

Maximum subarray of size HxW within a big 2D bit matrix

I have a big NxN bit array with K ones (everything else is zero). Coordinates of all non-zero points are known - in other words this NxN array can be represented as an array of K pairs each containing x and y coords of a non-zero point. Given a…
Igor
  • 163
  • 6
2
votes
0 answers

Matrix creation with indexed assignment: what is the logic when the dimensions don't match?

I am puzzled by the following: A(1,:) = zeros(1,1,5); % 1x5 A(1,:) = zeros(1,1,1,5); % 1x5 A(1,:) = zeros(1,1,1,1,5); % 1x5 The leading singleton dimensions get ignored. A(:,1) = zeros(1,1,5); % 5x1 A(:,1) = zeros(1,1,1,5); % 5x1 A(:,1) =…
geoffrey
  • 2,080
  • 9
  • 13
1
2
3
12 13