How do I convert a 2X2 matrix to 4X4 matrix in MATLAB?

后端 未结 7 1015
無奈伤痛
無奈伤痛 2020-12-03 23:26

I need some help in converting a 2X2 matrix to a 4X4 matrix in the following manner:

A = [2 6;
     8 4]

should become:

B =         


        
7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-04 00:23

    A = [2 6; 8 4];
    % arbitrary 2x2 input matrix
    
    B = repmat(A,2,2);
    % replicates rows & columns but not in the way you want
    
    B = B([1 3 2 4], :);
    % swaps rows 2 and 3
    
    B = B(:, [1 3 2 4]);
    % swaps columns 2 and 3, and you're done!
    

提交回复
热议问题