Error using vertcat Dimensions of arrays being concatenated are not consistent.
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
matrix1 = input("matrix 1 is \n");
matrix2 = input("matrix 2 is \n");
[M, N] = size(matrix1);
[P, Q] = size(matrix2');
if N == P
X = matrix1*matrix2
disp(X)
else
fprintf("Matrix multiplication can't be done.")
end
This is my code and we are tasked to do simple multiplication of matrices. This works fine in 2x2 or 1x1 or even 16x16 matrices but when it comes to 1x3 or 3x4 or 5x7, it doesnt work anymore. Thank you for answering
2 comentarios
KSSV
el 16 de Sept. de 2020
What is c, d, I, J? Variables are not defined, how do you expect us to help you?
Respuestas (2)
David Hill
el 16 de Sept. de 2020
matrix1 = input("matrix 1 is \n");
matrix2 = input("matrix 2 is \n");
[M, N] = size(matrix1);
[P, Q] = size(matrix2);
if N == P
X = matrix1*matrix2;
disp(X)
else
fprintf("Matrix multiplication can't be done.")
end
VBBV
el 9 de Dic. de 2021
matrix1 = rand(1,3)%input("matrix 1 is \n"); This is example of 1 x3 matrix
matrix2 = rand(3,3)%input("matrix 2 is \n");
[M, N] = size(matrix1);
[P, Q] = size(matrix2);
if N == P
disp('The product is ')
X = matrix1.*matrix2
else
fprintf("Matrix multiplication can't be done.")
end
0 comentarios
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!