Matrix dimensions must agree when using .*
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Amy Phan
le 21 Mai 2017
Commenté : Niladri Halder
le 9 Août 2022
Hi all,
I've been trying to multiply two matrices together and I can not find where I went wrong. I'm trying to multiply the matrix and it's transpose together however I am getting the error, "Matrix dimensions must agree."
The two matrices contain the following information:
Name Size Bytes Class Attributes
D_tranpose 6x16384 98304 uint8
D 16384x6 98304 uint8
Does anyone have any ideas? Thanks in advance
2 commentaires
Stephen23
le 21 Mai 2017
@Amy Phan: you need to learn about the differences between array and matrix operations:
Niladri Halder
le 9 Août 2022
nn2_p = nn2{nImage}.*mask_s;
Matrix dimensions must agree.
Please Help. Thank you.
Réponse acceptée
Walter Roberson
le 21 Mai 2017
C = A.*B is element-by-element multiplication, for which unless one of A or B is a scalar, the result C(J,K) = A(J,K).*B(J,K) . For that to work, the matrices must be the same size.
Perhaps you want D_tranpose * D which would be algebraic matrix multiplication, and would give you a 6 x 6 result for those matrices.
2 commentaires
Walter Roberson
le 22 Mai 2017
double(D_tranpose) * double(D)
When you do algebraic matrix multiplication involving uint8 the result is quite likely to exceed the capacity of uint8, so you would not want to use * directly between uint8 even if it were permitted.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!