使用函数法、拼接法、拼接函数法和变形函数法,按照要求创建以下短阵:A 为 3×4的全1矩阵、B为3x3的0矩阵、C为3x3的单位阵、D为3x3的魔方阵、E由C 和D纵向拼接而成、F抽取E的2~5行元素生成、G由下经变形为3x4的矩阵而得、以G为子矩阵用复制函数(repmat)生成 6x8 的大矩阵H
时间: 2023-05-30 18:08:04 浏览: 140
函数法:
A = ones(3,4);
B = zeros(3,3);
C = eye(3);
D = magic(3);
E = [C;D];
F = E(2:5,:);
G = [F(:,1:2), sum(F(:,3:4),2)];
H = [repmat(G,2,2), repmat(A,2,1); repmat(B,2,2), repmat(D,1,2)];
拼接法:
A = [1 1 1 1; 1 1 1 1; 1 1 1 1];
B = [0 0 0; 0 0 0; 0 0 0];
C = [1 0 0; 0 1 0; 0 0 1];
D = [8 1 6; 3 5 7; 4 9 2];
E = [C;D];
F = E(2:5,:);
G = [F(:,1:2), sum(F(:,3:4),2)];
H = [repmat(G,2,2), [A;A]; [B,B;D,D]];
拼接函数法:
A = ones(3,4);
B = zeros(3,3);
C = eye(3);
D = magic(3);
E = vertcat(C,D);
F = E(2:5,:);
G = [F(:,1:2), sum(F(:,3:4),2)];
H = [repmat(G,2,2), repmat(A,2,1); repmat(B,2,2), repmat(D,1,2)];
变形函数法:
A = ones(3,4);
B = zeros(3,3);
C = eye(3);
D = magic(3);
E = vertcat(C,D);
F = E(2:5,:);
G = [F(:,1:2), sum(F(:,3:4),2)];
H = [repmat(G,2,2), [repmat(A(1,:),2,1);repmat(A(2,:),2,1)];[repmat(B(1,:),2,2),repmat(D(1,:),1,2)];[repmat(B(2,:),2,2),repmat(D(2,:),1,2)];[repmat(B(3,:),2,2),repmat(D(3,:),1,2)]];
阅读全文