Search code examples
matlabfor-looprotationplotaxes

Is there any way to make an iterative plot that rotates the axes at every iteration


I would like to make a plot then rotate the x-y axes by an angle; then make the same plot again on the rotated axes, then rotate axes again for the next similar plot

Something like this:

hold all;

for k= 0:1:10
    % rotate-axis-about-origin(angle * k)
    plot(XY(:,1),XY(:,2));
end

Is there any way to achieve what I am proposing?


Solution

  • Use a rotation matrix inside the loop:

    hold all;
    
    % test vector and matrix
    x = (1:10)';
    y = x.^2;    
    XY0 = [x y];
    
    angle = 1/180*pi;   % 1 degree
    
    for k= 0:1:10
        % rotate-axis-about-origin(angle * k)
        rot = [cos(angle*k) sin(angle*k);-sin(angle*k) cos(angle*k)];
        XY = XY0*rot;
        plot(XY(:,1),XY(:,2));
    end
    

    XY0 is the original matrix and XY varies each step.

    Hope this is what you are looking for.