How to rotate image and axes together on Matlab?

前端 未结 1 1886
孤城傲影
孤城傲影 2021-01-17 08:20

Code 1 where flipping vertically and/or horizontally does not affect axes(); Code 2 where proposed solution does not yield the expected output

         


        
相关标签:
1条回答
  • 2021-01-17 08:22

    If I correctly understand your question, then this code does what you look for:

    x = 5:8;
    y = 3:6;
    C = reshape(0:2:22,4,3).';
    C2 = fliplr(C); % horizontal flip
    C3 = flipud(C); % vertical flip
    C4 = rot90(C,2); % horizontal+vertical flip
    
    % the answer starts here:
    subplot(2,2,1), imagesc(x,y,C)
    set(gca,'XTick',x,'XTickLabel',x,...
         'YTick',y,'YTickLabel',y)
    subplot(2,2,2), imagesc(x,y,C2)
    set(gca,'XTick',x,'XTickLabel',fliplr(x),...
         'YTick',y,'YTickLabel',y)
    subplot(2,2,3), imagesc(x,y,C3)
    set(gca,'XTick',x,'XTickLabel',x,...
         'YTick',y,'YTickLabel',fliplr(y))
    subplot(2,2,4), imagesc(x,y,C4)
    set(gca,'XTick',x,'XTickLabel',fliplr(x),...
         'YTick',y,'YTickLabel',fliplr(y))
    

    the result:

    I changed you x and y from 2-element vectors, but it works also if:

    x = [5 8];
    y = [3 6];
    

    BTW...

    Instead of manipulating C and create C2...C4, you can just write:

    subplot 221, imagesc(x,y,C)
    subplot 222, imagesc(fliplr(x),y,C)
    subplot 223, imagesc(x,fliplr(y),C)
    subplot 224, imagesc(fliplr(x),fliplr(y),C)
    

    and add the manipulation on the axis after each call to subplot like before.


    Edit:

    Using your sizes and limits of the vectors:

    x = linspace(0,10,6);
    y = linspace(0,180,19); % no need to plot each label
    N = 3613;
    C = diag(1:N)*ones(N)+rot90(diag(1:N)*ones(N)); % some arbitrary matrix 
    

    where all the rest of the code above remains the same, I get the following result:

    0 讨论(0)
提交回复
热议问题