how to fix error inner matrix dimensions must agree problem

11 次查看(过去 30 天)
I got this error when i did the multiplication of matrices that consist of both complex numbers ,integers and zeros shown below:
??? Error using ==> mtimes
Inner matrix dimensions must agree.
W1 = P1.*Q1.*V.*P2.*Q2;

采纳的回答

Image Analyst
Image Analyst 2015-1-24
You're doing element-by-element multiplication, NOT matrix multiplication, so that means the rows of all 5 matrixes must be the same and the columns of all 5 matrixes must be the same. You do not have that.
But your partial error message indicates that it thinks it's doing a matrix multiplication, not an element-by-element operation. So the columns of the left matrix must match the number of rows in the left matrix. You don't have that either.
Please post the ENTIRE ERROR MESSAGE . This means ALL the red text , not just a paraphrased subset of the message like you did, which probably had an error when you re-wrote it. I know you didn't give the entire error message because the entire error message will always give line numbers and what you showed us did not have that.
  4 个评论
segun
segun 2015-1-24
??? Error using ==> times Matrix dimensions must agree.
Error in ==> CASCADED at 68 W1=P1.*Q1.*V.*P2.*Q2;
Image Analyst
Image Analyst 2015-1-24
Aaaaaaand, you did it again. OK, let's just forget about that and assume you wrote it (the partial error message) in here correctly. Let's just look at one of the products - the product of V and P2. So V.*P2 is a 2*2 multiplied by a 2*101. Can you give me an actual numerical example of how that would work? So you multiply V(1,1) by P(1,1), and you multiply V(1,2) by P(1,2), and you multiply V(2,1) by P(2,1), and you multiply V(2,2) by P(2,2). OK, fine so far. But what elements of V are you going to multiply the (1,3) element of P2 by? There is no (1,3) element of V! Don't you see? You can't do that.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by