我需要通过以下方式将2X2矩阵转换为4X4矩阵的一些帮助:
A = [2 6; 8 4] 应该变成:
B = [2 2 6 6; 2 2 6 6; 8 8 4 4; 8 8 4 4] 我该怎么做?
回答:
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!
更多&回答...