Hi Anton,
To display matrices in the command window in a way that resembles how you might write them on paper, you can use MATLAB's 'fprintf' function to format the output. Here's a solution that aligns the matrices and the operation symbols (+ and =) as you described:
% Define matrices A and B
A = [2 4; 3 5];
B = [8 7; 9 0];
C = A + B;
% Call the function to display the matrices
display_matrices(A, B, C);
% Define a function to display the matrices
function display_matrices(A, B, C)
% Get the number of rows
[rows, ~] = size(A);
% Print each row of matrices A, B, and C
for i = 1:rows
fprintf('%d %d %d %d %d %d\n', A(i,1), A(i,2), B(i,1), B(i,2), C(i,1), C(i,2));
% Print the operation symbols after the first row
if i == 1
fprintf(' + = \n');
end
end
end
You can include an if-else condition within that function to modify it to show the matrix operation for different arithmetic operators as well.
I hope this helps!