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
    4 vues (au cours des 30 derniers jours)
  
       Afficher commentaires plus anciens
    
A =[1 2;3 4];
B=[2 3;5 6];
C=[A;B] ( should be in 2*2 )
6 commentaires
Réponses (1)
  Walter Roberson
      
      
 le 20 Mai 2023
        
      Modifié(e) : Walter Roberson
      
      
 le 20 Mai 2023
  
      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
2 commentaires
  Walter Roberson
      
      
 le 20 Mai 2023
				
      Modifié(e) : Walter Roberson
      
      
 le 21 Mai 2023
  
			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
Voir également
Catégories
				En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange
			
	Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




