if true % code
endclcclear allclose allif true % codeendglobal yglobal y1global h_recglobal h_rec1if true % codeendh_fig=figure;set(h_fig, 'KeyPressFcn', @kpfcn)if true % codeendaxis([-10 10 -10 10])if true % codeendx=[2 2 4 4];y=[2 4 2 4];h_rec= patch(x,y,'k');if true % codeendx1=[2 4 2 4];y1=[2 2 4 4];h_rec1= patch(x1,y1,'k');if true % codeendrefreshdatafunction kpfcn(~, event)global yglobal y1global h_recglobal h_rec1if true % codeendswitch event.Key case 'uparrow' x=[2 2 4 4]; x1=[2 4 2 4]; y=y+[1 1 1 1]; y1=y1+[1 1 1 1]; h_rec=patch(x,y,'k') h_rec1=patch(x1,y1,'k') case 'downarrow' x=[2 2 4 4]; x1=[2 4 2 4]; y=y-[1 1 1 1]; y1=y1-[1 1 1 1]; h_rec=patch(x,y,'k') h_rec1=patch(x1,y1,'k')if true % codeendendend
MATLAB: How to Move the Patches fluidly without Leaving a Marking of the Patch at the previous Location
keypressfcn
Best Answer