Win: Help with Screen(‘CopyWindow’...) problem?

Help with Screen(`CopyWindow'...) problem?

Hi. I hope this is a simple problem. I am trying to use DriftDemo to
make drifting gratings that fill a monitor screen but am getting an
error at SCREEN(`CopyWindow',...) when trying to write the
precomputed
images from OffscreenWindows to the main window (my monitor). I'm
using a WinXP PC and Matlab v.6.5 R13.

The code in DriftDemo.m computes the images as squares and works
great. I can precompute the grating images as rectangles using this
modified demo code shown below. This only differs from DriftDemo.m by
using a rectangular set of points in [x, y]=meshgrid... and using [0 0
w h] instead of size(m) to set the dimensions of the OffscreenWindow.
I've tried to highlight the differences using "-->"
below:

------------
% compute each frame of the movie
frames=10; % temporal period, in frames, of the drifting grating
for i=1:frames
phase=(i/frames)*2*pi;

% grating
--> [x,y]=meshgrid(-100:100,-50:50);
angle=30*pi/180; % 30 deg orientation.
f=0.05*2*pi; % cycles/pixel
a=cos(angle)*f;
b=sin(angle)*f;
m=sin(a*x+b*y+phase);

--> [h w]=size(m); % height and width of the image
--> w(i)=SCREEN(whichScreen,'OpenOffscreenWindow',0,[0 0 w h]);
SCREEN(w(i),'PutImage',gray+inc*m);
end
---------------

When I check to see the sizes of the w(i) screens using
"rect=Screen(w(i),'Rect')", Matlab reports the
correct dimensions:
rect = 0 0 201 101

However, trying to write each of these w(i) screens (containing the
sequential images of the drifting grating) to the monitor fails at
Screen(`CopyWindow',...) in the loop below:

-------------
% show the movie
r=SCREEN(w(1),'Rect');
rr=CenterRect(r,screen(window,'Rect'));
n=round(0.5*FrameRate(window)); % x seconds
for i=1:n;
SCREEN(window,'WaitBlanking');
--> SCREEN('CopyWindow',w(1+mod(i,frames)),window,r,rr);
end;
---------------

The "w(1+mod(i,frames))" part simply cycles through the
images in a repeating loop (i = 1, 2, 3, 4, 1, 2, 3, 4, 1, ...) to
make a movie by repeating the image cycle for a certain amount of
time.

When I run this, I get this error:
---------
??? Usage:

SCREEN('CopyWindow',srcWindowPtr,dstWindowPtr,[src
Rect],[dstRect],[copyMode])

Error in ==> C:\MATLAB6p5\toolbox\PsychToolbox\PsychBasic\Screen.dll
Error in ==> C:\MATLAB6p5\toolbox\PsychToolbox\Psy
chDemos\matrixtest8.m
On line 42 ==> SCREEN('CopyWindow',w(1+mod(i,frames)),window,r,rr);
---------

Matlab reports that "r" (the dimensions of the first grating
screen in memory) is now [0 0 1024 768] instead of the original 201 x
101 size.

Any idea what I'm doing incorrectly here? Does this have
anything to do with the fact that windows can't be arbitrary
sizes on
a PC? I don't have much experience with PsychToolbox and so don't
understand window behavior very well.

Any help is much appreciated!

Thank you,
Rene'
Whoops! (an embarrassed whoops at that :) !)

Of course. Never mind, nothing to see here :)

I appreciate your taking a look at it. My addled brain was seeing the
characters "w(i)" as a different variable than "w".

Now to repair that forehead-sized hole in the wall...

Thanks a bunch,
Rene'

--- In psychtoolbox@yahoogroups.com, "BrSchnitz" <brschnitz@y...>
wrote:
> I'm not sure if this is particular to your code, or just the
example
> that you posted, but you seem to be using the variable 'w'
> twice...once for window pointers, and a second time to store window
> width. This seems to be the problem, as I can run your code after
> changing the following lines:
>
> --> [h w]=size(m); % height and width of the image
> --> w(i)=SCREEN(whichScreen,'OpenOffscreenWindow',0,[0 0 w h]);
>
> to
>
> --> [h wid]=size(m); % height and width of the image
> --> w(i)=SCREEN(whichScreen,'OpenOffscreenWindow',0,[0 0 wid h]);
>
>
> Hope this helps!
> Brian