Search code examples
matlabmatrixmachine-learningsubmatrix

How to create a sub-matrix in MATLAB


I have this work which I have to do by creating a sub-matrix out of a given data set. I will explain it below.

Suppose, I have the data set as:

100  200  300  400  500  600
101  201  301  401  501  601
102  202  302  402  502  602

So, I want to create sub-matrices as follows:

For the first iteration ->

[[101  201  301  401  501]
[102  202  302  402  502]]

and

[[601]
[602]]

For the second iteration ->

[[100  200  300  400  500]
[102  202  302  402  502]]

and

[[600]
[602]]

And so on... The process will continue till the number of rows in the main/starting matrix.

In short, I want a LOO (leave one out) implementation of this data set, so that I can further work on it.

If you guys have any idea on how to do it, please share it. :)


Solution

  • Assuming A is the main matrix, a1 and a2 will be your first set of sub-matrices and b1 and b2 will be the second set of sub-matrices.

    >> A=[100  200  300  400  500  600
        101  201  301  401  501  601
        102  202  302  402  502  602];
    >> a1=A(2:3,1:5)
    
        a1 =
    
       101   201   301   401   501
       102   202   302   402   502
    
    >> a2=A(2:3,6)
    
    a2 =
    
       601
       602
    
    >> b1=A(1:2,1:5)
    
    b1 =
    
       100   200   300   400   500
       101   201   301   401   501
    
    >> b2=A(1:2,6)
    
    b2 =
    
       600
       601