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

1 view (last 30 days)
mu=[1 1]';
p=0;
sigma=[1 2*p;2*p 4];
x= mu+sigma.*randn(1000,2);

Answers (2)

Image Analyst
Image Analyst on 17 Mar 2016
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 Comments
Walter Roberson
Walter Roberson on 18 Mar 2016
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 on 18 Mar 2016
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.

Sign in to comment.


Walter Roberson
Walter Roberson on 18 Mar 2016
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.

Community Treasure Hunt

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

Start Hunting!