Asked by Makrim
on 16 May 2015

Suppose I have a matrix M of 5x4 dimension (this is represent an image) :

M =[3 4 8 9;

1 6 7 3;

9 8 3 1;

1 2 2 0;

7 2 3 5];

I would like to rotate it around the origin (0,0) with an angle of 45°.

From what I have found on the net , I have to multiply M by Rotation Matrix R is as follow :

R = [ cosd(45) -sind(45);

sind(45) cosd(45)]

Now do I simply multiply M by R and get a rotated matrix ??? like this :

rotM = R*M

I think I will have a problem of dimensions ? please how to rotate a matrix 5x4 by 45° around the origin (0,0)?

PS: imrotate, rot90, flip* and rotate is not suitable here, thank you in advance.

Answer by Walter Roberson
on 16 May 2015

Use matrix multiplication, the * operator, not the .* operator.

Remember that in MATLAB, sin() and cos() take radians as the argument, not degrees. You can use sind() and cosd() for degrees.

Makrim
on 16 May 2015

When I use * I get this error :

Error using *

Inner matrix dimensions must agree.

Walter Roberson
on 16 May 2015

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 2 Comments

## David Young (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/217065-how-to-rotate-a-matrix-5x4-by-45-around-the-origin-0-0#comment_285771

## Image Analyst (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/217065-how-to-rotate-a-matrix-5x4-by-45-around-the-origin-0-0#comment_285774

Sign in to comment.