MATLAB: Error in ‘DrawTexture’

drawtextureload scriptscreen

Hi everybody,
I'm quite new to the whole matlab experience and I'm hoping someone can help me out with this.
I'm using a script to convert images to texture/mat files, that has worked before. But when put it in my main script and run it, I get the following error, anybody out there who can help =)?
Thank you so much!
Error in function DrawTexture: Missing argument
Discrepancy between a specified and supplied argument:
Specified Argument Description:
direction: Input
position: 2
presence:forbidden
formats allowed:
double
minimum M: 1
maximum M: 1
minimum N: 1
maximum N: 1
minimum P: 1
maximum P: 1
Provided Argument Description:
direction: Input
position: 2
presence: absent
Error using Screen
Usage:
Screen('DrawTexture', windowPointer, texturePointer [,sourceRect] [,destinationRect] [,rotationAngle] [, filterMode]
[, globalAlpha] [, modulateColor] [, textureShader] [, specialFlags] [, auxParameters]);
Error in encoding_2 (line 219)
Screen('DrawTexture', win, tex(trial_order(trial+1))); %uses loadJPG_as_Texture.m

Best Answer

Yes, sorry! It was so simple in the end:
1) I made sure that only jpg's are in the stimulus folder (as the transformation function posted above counts all files, which gives an error later in the script when it seems as if there are more files to be read in then there actually are)
2) when writing your script as a function 'tex' is not a texturepointer but refers to something else (as @Walter suggested in the beginning). So, when converting jpg to texture, instead of saying
tex(nfile) = Screen('MakeTexture', win, img);'
I changed it to
imgtex(nfile) = Screen('MakeTexture', win, img);'.
In the main script, it now reads
Screen('DrawTexture', win, imgtex(trialList.stimNr(trial)));
btw. tested it under the scanner (fMRI) yesterday and it works like a charm =)
Thank you guys again!