fork download
  1. % Define the matrices A, B, and C
  2. A = [3 -2 1; 6 8 -5; 7 9 10];
  3. B = [6 9 -4; 7 5 3; -8 2 1];
  4. C = [-7 -5 2; 10 6 1; 3 -9 8];
  5.  
  6. % Create a 3D array D where each matrix is a layer
  7. D = cat(3, A, B, C);
  8.  
  9. % Find the largest element in each layer
  10. max_A = max(A(:)); % Max of the first layer (A)
  11. max_B = max(B(:)); % Max of the second layer (B)
  12. max_C = max(C(:)); % Max of the third layer (C)
  13.  
  14. % Find the largest element in the entire array D
  15. max_D = max(D(:));
  16.  
  17. % Display the results
  18. fprintf('Largest element in matrix A: %d\n', max_A);
  19. fprintf('Largest element in matrix B: %d\n', max_B);
  20. fprintf('Largest element in matrix C: %d\n', max_C);
  21. fprintf('Largest element in the entire array D: %d\n', max_D);
  22.  
Success #stdin #stdout 0.11s 46916KB
stdin
Standard input is empty
stdout
Largest element in matrix A: 10
Largest element in matrix B: 9
Largest element in matrix C: 10
Largest element in the entire array D: 10