how to create a 2*2 matrix by combining two matrices with size of 2*2 ie A and B are 2*2 and i want to get C also 2*2

조회 수: 2 (최근 30일)
A =[1 2;3 4];
B=[2 3;5 6];
C=[A;B] ( should be in 2*2 )
  댓글 수: 6

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2023년 5월 20일
편집: Walter Roberson 2023년 5월 20일
A =[1 2;3 4];
B=[2 3;5 6];
switch randi(12)
case 1; C = A + B;
case 2; C = A - B;
case 3; C = B - A;
case 4; C = A .* B;
case 5; C = A * B;
case 6; C = B * A;
case 7; C = A ./ B;
case 8; C = B ./ A;
case 9; C = A.^B;
case 10; C = B.^A;
case 11; C = mod(A,B);
case 12; C = mod(B,A);
end
C
C = 2×2
12 15 26 33
  댓글 수: 2
Walter Roberson
Walter Roberson 2023년 5월 20일
편집: Walter Roberson 2023년 5월 21일
A =[1 2;3 4];
B=[2 3;5 6];
fcns = {@lt, @le, @eq, @gt, @ge, @and, @or, @times, @mtimes, @plus, @minus, @rdivide, @mrdivide, @ldivide, @mldivide, @min, @max};
fnames = ["<", "<=", "==", ">=", ">", "&", "|", ".*", "*", "+", "-", "./", "/", ".\", "\", "min", "max"];
for order = 1 : 2
switch order
case 1; first = A; second = B; firstname = "A"; secondname = "B";
case 2; first = B; second = A; firstname = "B"; secondname = "A";
end
for fidx = 1 : length(fcns)
opname = firstname + " " + fnames(fidx) + " " + secondname + " = ";
value = fcns{fidx}(first, second);
disp(opname);
disp(value);
disp("");
end
end
A < B =
1 1 1 1
A <= B =
1 1 1 1
A == B =
0 0 0 0
A >= B =
0 0 0 0
A > B =
0 0 0 0
A & B =
1 1 1 1
A | B =
1 1 1 1
A .* B =
2 6 15 24
A * B =
12 15 26 33
A + B =
3 5 8 10
A - B =
-1 -1 -2 -2
A ./ B =
0.5000 0.6667 0.6000 0.6667
A / B =
1.3333 -0.3333 0.6667 0.3333
A .\ B =
2.0000 1.5000 1.6667 1.5000
A \ B =
1.0000 0.0000 0.5000 1.5000
A min B =
1 2 3 4
A max B =
2 3 5 6
B < A =
0 0 0 0
B <= A =
0 0 0 0
B == A =
0 0 0 0
B >= A =
1 1 1 1
B > A =
1 1 1 1
B & A =
1 1 1 1
B | A =
1 1 1 1
B .* A =
2 6 15 24
B * A =
11 16 23 34
B + A =
3 5 8 10
B - A =
1 1 2 2
B ./ A =
2.0000 1.5000 1.6667 1.5000
B / A =
0.5000 0.5000 -1.0000 2.0000
B .\ A =
0.5000 0.6667 0.6000 0.6667
B \ A =
1.0000 -0.0000 -0.3333 0.6667
B min A =
1 2 3 4
B max A =
2 3 5 6

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by