2017-06-08 31 views
1

如何让这个矩形从左上角移动到右下角?使用tot功能的矩形移动

clear all 
close all 
clc 
n=10; 
h=1; 
for t=0:n-1 
    clf; 
    axis([0 sum(1:n) 0 sum(1:n)]); 
    axis manual 
    tot = sum(0:t); 
    patch([tot tot+(t+1)*h tot+(t+1)*h tot],[tot tot tot+(t+1)*h tot+(t+1)*h],... 
     [2 6 3 7],'EdgeColor','none','FaceAlpha',(1-(t+1)*.7/n)); 
    pause(1/6) 
end 

此外,尝试在某处使用此功能。 sum(1:t)-tot-(t+1)*h

+0

请接受帮助你的答案,以确认主题是否接近。 – EBH

回答

1

你可以计算补丁函数y位置不同,但是从当前的代码,最简单的变化将是扭转Y轴方向:

axis ij; % put this before patch 
1

你只需要substruct您y坐标从总高度sum(0:n)

patch([tot tot+(t+1)*h tot+(t+1)*h tot],... 
    sum(0:n)-[tot tot tot+(t+1)*h tot+(t+1)*h],... 
    [2 6 3 7],'EdgeColor','none','FaceAlpha',(1-(t+1)*.7/n));