MATLAB: Matrix into Sub matrix of length 8

homeworkMATLAB

Suppose I have a matrix like this A = [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24] (Length of a Matrix is always multiple of 8). I want to break it into sub matrices of length 8. I use reshape function but it does not work. Needs your help.

Best Answer

  • What did you try for reshape? Did you try reshape(A, [], 8)?
    A=[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24];
    a8 = reshape(A, [], 8)
    % For example, to get 2nd subarray of 8 specify group as 1st index and : as second index.
    out = a8(2,:)