i want to divide a matrix of n x m in smaller equal sized square matrix of size p x p..

i want to divide a matrix of n x m in smaller equal sized square matrix of size p x p..

pl help with this code.....

import java.util.Scanner;

class seg {
    int seg[][] = new int[4][4];
}

class segment
{

   public static void main(String args[])
   {
      int m, n, i, j = 0;

      Scanner in = new Scanner(System.in);
      System.out.println("Enter the number of rows and columns of matrix");
      m = in.nextInt();
      n = in.nextInt();

      int matrix[][] = new int[m][n];

      System.out.println("Enter the elements of matrix\n");

      for ( i = 0 ; i < m ; i++ )
         for ( j = 0 ; j < n ; j++ )
            matrix[i][j] = in.nextInt();

      System.out.println("entered matrix is:\n");
      for ( i = 0 ; i < m ; i++ )
      {
         for ( j = 0 ; j < n ; j++ )
               System.out.print(matrix[i][j]+"\t");

            System.out.print("\n");
      }


      seg s[]=new seg[10];

      int q, k=0,c=0,d=0;

     if(c%(m+i)!=0 || d%(n+j)!=0)
      {
      for(i=c;i<c+4;i++)
      {
          for(j=d;j<d+4;j++)
             if(i>=m || j>=n)
                  s[k++].seg[i][j]=0;//zero padding
              else
                  s[k++].seg[i][j]=matrix[i][j];


       }
      c=c+4;
      d=d+4;
      }
 
      System.out.println("segments are\n");
     
     q=k;
     do{
      for ( i = 0 ; i < 4 ; i++ )
      {
         for ( j = 0 ; j < 4 ; j++ )
               System.out.print(s[q--].seg[i][j]+"\t");
        System.out.print("\n");
      }
     }while(q!=0);


    }
    }

Edited 4 Years Ago by ~s.o.s~: Added code tags, please learn to use them.

You will have to elaborate the problem.

A simple 7x6 matrix is shown for example

S=

23 34 34 12 34 12
45 43 34 67 76 23
23 23 67 78 23 90
12 23 12 56 78 90
45 23 67 45 12 32
67 24 12 78 90 23
89 12 09 10 20 02


after dividing matrix into equal sized square matrix of size 4 x 4


I1=

23 34 34 12
45 43 43 67
23 23 67 78
12 23 12 56


I2=

45 23 67 45
67 24 12 78
89 12 09 10
00 00 00 00


I3=

34 12 00 00
76 23 00 00
23 90 00 00
78 90 00 00


I4=

12 32 00 00
90 23 00 00
20 02 00 00
00 00 00 00

Edited 4 Years Ago by mneha67: n/a

This article has been dead for over six months. Start a new discussion instead.