0

我的代码:

Screen('OpenWindow', 0, [0 0 0], [0 0 600 600])
Screen('FillRect', win, [0 255 0 ], [0 0 50 50]);
Screen('Flip', win);

我了解记录在案的行是:

Screen('FillRect', windowPtr [,color] [,rect] )

windowPtr只是一个占位符,需要用变量名替换以识别此特定形状。但是,当我使用 win 识别它时,我不断收到错误消息:

未定义的函数或变量“win”。
Practice_Script_1 (line 17)
Screen('FillRect', win, [0 255 0 ], [0 0 50 50]) 中的错误;

我不明白我做错了什么,这可能只是一些菜鸟的错误,这真的让我很沮丧。

4

1 回答 1

0

I don't have the Psychtoolbox, but this error message typically means that the (in this case) win variable is not defined. Have you initialized this variable prior to calling the above lines of code?

The following link creating experiments using MATLAB and Psychtoolbox has some sample code and they define the win variable as

win = Screen('OpenWindow',0, [900 900 1000], [10,10, 1100,1100]);

You will need to do something similar. Another link MATLAB cookbook does the following

% Initialize the screen with a black background
% rect is the coordinates of the screen
[win rect] = Screen('OpenWindow', 0, [0 0 0]);

ovalColor = [0 255 0];         % RGB color for the oval
rectColor = [255 0 0];         % RGB color for the rectangle
ovalRect  = [100 100 300 200]; % Coordinates [x1 y1 x2 y2]
rectRect  = [100 250 300 350]; % Coordinates [x1 y1 x2 y2]

Screen('FillOval', win, ovalColor, ovalRect);
Screen('FillRect', win, rectColor, rectRect);
Screen('Flip', win);

Try either option and see what happens.

于 2014-06-17T00:25:50.833 回答