MATLAB: Rotation meshgrid surface with the predefined angel(using rotation matrix)

.

Let's say:
x=1:0.2:1.8= [1 1.2 1.4 1.6 1.8];
y=2:0.2:3 = [2 2.2 2.4 2.6 2.8 3];
z=[2 5 2 2 2; 2.1 2.1 2.1 2.1 2.1; 2 2 2 2 2; 3 3 3 3 3; 1 1 1 1 1; 2.5 2.5 2.5 2.5 2.5]; %matrix 6-by-5
[X,Y] = meshgrid(x,y);
surf(X,Y,Z);% the plot show below
The question is: How can I rotate the plot data with the angel=10 (degree), counterclockwise about Z axis, & How can I plot the new meshgrid surface (using the new rotate data) as the below figure?
angel=10;
R=[cosd(angel) -sind(angel) 0;sind(angel) cosd(angel) 0;0 0 1];%the rotation matrix R

Best Answer

clear;clc;x = 1:0.2:1.8;
y = 2:0.2:3;
z=[ 2 5 2 2 2;2.1 2.1 2.1 2.1 2.1;2 2 2 2 2;3 3 3 3 3;1 1 1 1 1;2.5 2.5 2.5 2.5 2.5];
[X,Y] = meshgrid(x,y);
xyc = [mean(x), mean(y)];% Rotate about the center
angel = 30;
R = [cosd(angel), -sind(angel); sind(angel), cosd(angel)];
XY = xyc' + R * ([X(:) Y(:)]-xyc)';
XR = reshape(XY(1,:),size(X));
YR = reshape(XY(2,:),size(Y));
surf(X,Y,z);
hold on;surf(XR,YR,z);