MATLAB: Split 2 lines of a matrix

matrix

I have this 4×4 matrix.
I want to get lines 3 and 4 to put them up on the matrix, like:
0 1 1 1 1 1 1 1
1 1 1 1 to 0 1 1 1
1 1 1 1
I've made a 2×4 example to make things easier.
Thanks

Best Answer

  • B=[A(3:4,:);A]; % create new array keeping old
    A=[A(3:4,:);A]; % new array replaces/augments old
    More generically,
    N=2; % number rows at end to add to beginning
    A=[A(end-N+1:end,:);A]; % add N last lines at beginning