Can anybody help with persistant errors? (Matlab beginer)
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
LuS
el 5 de Ag. de 2015
Comentada: Walter Roberson
el 5 de Ag. de 2015
Hi all,
I am really new in Matlab and I am programming a small behavioral experiment with images.
Below is the script I am (desperately) trying to run, but keep encountering many errors, specifically 'Undefined function of variable 'wPtr'.
Whenever I evaluate the selection of every section, it seems Ok, but as soon as I try to run the script, errors pop out!
Thank you!
function X
%open the screen
[wPtr,rect]=Screen('OpenWindow',max(Screen('Screens')));
xCenter=rect(3)/2;
yCenter=rect(4)/2;
%Create textures
duckData=imread('C:\Users\louah\Desktop\StimuliEEG_semanticpriming\duck.jpg');
duckTexture=Screen('MakeTexture', wPtr,duckData);
BananaData=imread('C:\Users\louah\Desktop\StimuliEEG_semanticpriming\Banana.jpg');
BananaTexture=Screen('MakeTexture', wPtr,BananaData);
%Get size of image (both images the same size in this example)
%imageHeight
%imageWidth
%colorChannels
[imageHeight, imageWidth,colorChannels]=size(duckData);
%Set up left and right picture locations
gap=100; %distance of pics from center
leftRect=[xCenter-gap-imageWidth, yCenter-imageHeight/2, xCenter+imageHeight/2];
rightRect=[xCenter+gap, yCenter-imageHeight/2, xCenter+gap+imageWidth, yCenter+imageHeight/2];
%set up some vectors with our options
textures=[duckTexture, BananaTexture];
textureNames={'duck', 'Banana'};
rects={leftRect, rightRect};
rectNames={'left', 'right'};
%set up logfile
subjectCode=1;
logfilename=sprintf('%s_log.txt', subjectCode);
logfile=fopen(logfilename, 'a');
%set up response codes
duckCode=KbName('d');
BananaCode=KbName('b');
%hold correctness values
correctnessvalues=[];
%loop for 20 trials
for trial=1:20
%pick a random number 1 or 2
randTextureNum=randi(2);
%now use that number tp pick a texture
ourTexture=textures(randTextureNum);
%draw the pie
%windowPtr=wPtr
Screen('DrawTexture', wPtr, ourTexture, [], ourRect);
stimTime=Screen('Flip', wPtr);
[secs, keyPressed]=KbWait();
Screen('Flip', windowPtr);
response=find(keyPressed);
responseTime=secs-stimTime;
%figure out correctness
correct=0;
if randTextureNum==1
%duck picture was presented
if response==duckCode
correct=1;
end
elseif randTextureNum==2
%Banana picture was presented
if response==BananaCode
correct=1;
end
end
%save correctness
correctnessvalues(end+1)=correct;
%print out to file
fprintf(logfile, '%d\t%s\t%s\t%s\t%.3f\t%d\n', trial, textureNames{randTextureNum},...
rectNames{randRectNum}, KbName(response), responseTime, correct);
WaitSecs(.5);
end
0 comentarios
Respuesta aceptada
David Young
el 5 de Ag. de 2015
The assignment to wPtr in the first line of the function has been commented out. This means that no value has been given to this variable when it is used in the later call to Screen. So you need to either reinstate that first call to Screen or give wPtr a value some other way.
By the way, your file isn't a script, it's a function. It's worth reading up on the difference in the documentation or a textbook.
Also, note that there is a button for formatting code in questions, and it makes it much easier for people to read your question if you use it.
1 comentario
Walter Roberson
el 5 de Ag. de 2015
What is the error message you get for that? Please show the full traceback as it might be a problem in a routine you are calling.
Más respuestas (1)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!