urgent. ı can not fix this error " Error using * Inner matrix dimensions must agree. " on this code

1 次查看(过去 30 天)
mu=[1 1]';
p=0;
sigma=[1 2*p;2*p 4];
x= mu+sigma.*randn(1000,2);

回答(2 个)

Image Analyst
Image Analyst 2016-3-17
sigma is 2x2. The randn() gives a 1000x2. And mu is a 2x1. So you can't multiply element-by-element when the size of ALL dimensions don't match up perfectly. And you can't add them either. I mean, how could you add a 2x1 to a 2x2 or to a 1000x2? You can't. You need to figure out better what you are trying to accomplish.
  3 个评论
Walter Roberson
Walter Roberson 2016-3-18
What does that N notation signify?
There is no indication there of what yi might be, only what y would be. If the two are intended to be the same, then you have the problem that the only way to do a matrix multiplication of a 2 x 2 matrix with a 1000 x 2 matrix is if the 1000 x 2 matrix is on the left rather than the right.
You should not be using ".*" for algebraic matrix multiplication: you should be using "*"
Image Analyst
Image Analyst 2016-3-18
I am not familiar with that notation either. I suggest you read prior to that page in the book to figure it out. Multiplying a 2x2 matrix by a list of N points/coordinates is like a rotation of the points in the 2-D plane about the origin, but I don't think that is what is intended here.

请先登录,再进行评论。


Walter Roberson
Walter Roberson 2016-3-18
Why are you still pursuing this question? You said it was "urgent" over 15 hours ago. Nothing short of a natural disaster or a person on an operating table can remain "urgent" for 15 hours.

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by