Hannah - how have you created the gratings pattern? As an image (2D array) or using multiple graphics objects that you have created drawn as black and white vertical bars? If the former, then you will be able to shift the image to the right (or left) by manipulating the array data. For example, suppose that you have create a 256x256 image of 16 alternating black and white (vertical) bars.
nRows = 256;
nCols = 256;
numBars = 16;
barWidth = nCols/numBars;
grtPattern = zeros(nRows,nCols);
for k=1:numBars
if mod(k,2) == 0
grtPattern(:,(k-1)*barWidth+1:k*barWidth) = 255;
end
end
h = image(grtPattern);
colormap([0 0 0 ; 1 1 1]);
set(gca,'xtick',[], 'ytick', []);
set(gca,'xticklabel',[], 'yticklabel',[]);
The above just creates the pattern. To move the pattern to the right, we remove the last column, shift the remaining columns to the right, and then insert the last column where the first one was (i.e. we wrap the columns around).
while true
lastCol = grtPattern(:,end);
grtPattern(:,2:end) = grtPattern(:,1:end-1);
grtPattern(:,1) = lastCol;
set(h,'CData',grtPattern);
pause(0.5);
end
We update the CData property of the image handle h on each iteration of the loop, pausing for half a second before continuing with the next "movement".