Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Matlab: how to extract blocks from a large matrix

  1. Aug 4, 2009 #1
    Hi,
    I have a 24000x24000 sparse matrix. I want to extract 4 blocks out of it;
    (0,0) to (6000,6000)
    (6001,6001) to (12000,12000)
    (12001,12001) to (18000,18000)
    (18001,18001) to (24000,24000)

    By use of those my aim is to make a block diagonal matrix using matlab command 'blkdiag' .

    Can anyone please help me with the matlab code to extract those 4 blocks.
    Thank you so much.
     
  2. jcsd
  3. Aug 4, 2009 #2
    I haven't done it before but my guess, would be is you create an empty scarce matrix, and then equate ellements using the colin operator.
     
  4. Aug 5, 2009 #3
    You can use the semicolon to select, let your matrix be A, then the blocks you want to get is A1,A2,A3,A4
    Code (Text):

    [m,n] = size(A);
    A1 = A(1:6000,1:6000);
    A2 = A(1:6000,6001:n);
    A3 = A(6001:m,1:6000);
    A4 = A(6001:m,6001:n);
    AA = blkdiag(A1,A2,A3,A4);
     
     
  5. Aug 8, 2009 #4
    If im understanding you correctly, you want to extract a square matrix
    out of a larger matrix. if you want a section out of an array, you just call the array using those indecies. so uf your matrix is A:

    (0,0) to (6000,6000) would be

    A(1:6001,1:6001)

    Remember in Matlab array/matrix indexes start at 1 not 0.

    (6001,6001) to (12000,12000) would be

    A(6002:12001,6002:12001)

    and so on.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Matlab: how to extract blocks from a large matrix
Loading...