現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
Error in 'DrawTexture'
3 ビュー (過去 30 日間)
古いコメントを表示
Alix
2019 年 9 月 6 日
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
13 件のコメント
Walter Roberson
2019 年 9 月 6 日
I suspect that your win variable is empty
However this is a question about details of psychtoolbox involving things not present in MATLAB itself.
Alix
2019 年 9 月 6 日
Hi Walter,
Thank you for your answer. True, it's about PTB but I didn't know where else to ask this...
How can my win variable be empty? The previous parts of the experiment are showing up just fine on the screen...
% Open window
[win, winRect] = Screen('OpenWindow', screen, 0);
Walter Roberson
2019 年 9 月 6 日
Are you sure that tex() is returning a texturepointer ? tex() normally returns 1 if it is passed a character vector that is valid latex commands, and returns [] if it is passed anything else (including a character vector that is not valid latex)
Alix
2019 年 9 月 7 日
the tex() refers to the function i use (see below). it works fine when i don't use the main script as function, but when i do (input arguments only subjID and runNr) it won't do it anymore...
% CONVERT IMAGES TO MAT files
theDir = [pwd filesep]; % Returns directory where the script is located
cd(theDir)
dirStim = [theDir filesep 'stim_encoding' filesep]; % folder with stimuli;
% use filesep instead of / for uniformity
files=dir([dirStim '*.jpg']); % Retrieves all JPG files in folder
for nfile = 1:length(files)
stim(nfile).fname = files(nfile).name;
img = imread([dirStim stim(nfile).fname]);
tex(nfile) = Screen('MakeTexture', win, img); %previously window instead of win
clear img
end
Alix
2019 年 9 月 7 日
@Guillaume: I am sorry I posted it here, the psychtoolbox forum doesn't work nearly as well and quick as it does here and I figured you guys are experts so who knows =). But if this question is too specific to PTB, please feel free to ignore/close it.
thank you though for taking a look!
Guillaume
2019 年 9 月 7 日
There's no problem posting your question here and I certainly did not mean to discourage you from doing so. It's just that I don't think that many of us regulars here know much about the toolbox (I've never used it). Walter may be the only one who knows something about it, so I pointed you to a forum where you may have more chance of getting help.
Walter Roberson
2019 年 9 月 7 日
I have not had the toolbox installed for a while (or rather I have not booted from that old disk in some time.) If you posted the source we would have more chance. At the moment my suspicion is that you have a scope problem and that tex is not what you think it is.
Alix
2019 年 9 月 8 日
@Guillaume: was merly ment as a thank you and sorry
@Walter, do you mean post the script? Here it goes:
This is how far I got, and like I said when I don't use it as a function, it works for some reason, but it loads in 148 instead of 147 files (but says there are 148 which is true):
function encoding_2_function (subjID, runNr)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%% GENERAL SET UP %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% General Parameters
PsychDefaultSetup(2);
KbName('UnifyKeyNames');
rng('shuffle');
Screen('Preference', 'SkipSyncTests', 1); %adapt under scanner (0 or comment out)
theDir = [pwd filesep]; % Returns directory where the script is located (pwd = directory where script is in, filesep = slash that corresponds to your computer system) % cd = theDir
dirStim = [theDir 'stim_encoding' filesep]; % folder with stimuli;
% use filesep instead of / for uniformity
% Filename of outputfile
outputfile = [theDir 'DATA' filesep 'PS_Encoding_S' num2str(subjID) '.mat'];
%% Set the expected parameters
p.stimDur = 2.5; %stimulus duration 2.5sec
p.fixDur = 0.5; % fixation cross duration 0.5sec / ISI
p.trialDur = p.stimDur + p.fixDur; %trial duration 3sec
p.stimN = 148; %total number of stimuli
p.taskDur = p.trialDur * p.stimN; %total expected duration of task (444sec = 7.4min)
p.margin = 0.003; % time(in sec) responses are not recorded between changes of stimuli, dependent on calculations between each trial, keep as low as possible)
p.thankyou = 5; % time thank you screen stays on
p.scrDist = 630; %in mm at scanner
p.scrWidth = 340; %in mm at scanner
p.prePost = 1; % in sec (10 at scanner)
p.respKey = [71 66 89 82]; % at scanner green/left, blue/right, yellow/down; keyboard g,b,y,r (r not used)
p.respInst = {'links', 'rechts', 'onder'};
%fixation cross size manually set
p.fixCrossSize = [.6 .5 .1];
%% Prepare stimulus file
% csv, comma delimited
% TrialNum, Stim, Stimtype
% Stimtype: 1 = negative, 2 = neutral, 3 = positive
[TrialNum, Stim, Stimtype] = textread('stim_encoding.csv', '%f%s%f', ...
'headerlines', 1, 'delimiter', ',');
% Create random order of trials (stims presented) (seed set at beginning; rng(shuffle))
ntrials = length(TrialNum);
trial_order = randperm(ntrials);
%% Make the output list
trialList.SubjID(:,1) = repmat(subjID, 1, p.stimN); %C1: SubjId to be repeated in 1 row for amount of p.stimN
trialList.runNr(:,2) = repmat(runNr, 1, p.stimN); % C2: run Number
trialList.trialNum(:,3) = repmat(1:p.stimN, 1); % C3: write out 1 through last trial Number (1-148)
trialList.trialOrder(:,4) = repmat(trial_order, 1)'; %C4: stim num/order of trials random
% empty counters to be filled in as we move through loop:
trialList.stimOnset(:,5) = zeros(p.stimN, 1); %C5: stim onset
trialList.stimType(:,6) = zeros(p.stimN, 1); %C6: cathegory response/Stimtype
%trialList(:,7) =
trialList.idealOnset(:,8) = p.prePost:p.trialDur:(p.stimN*p.trialDur)+(p.prePost-p.trialDur); %C8: ideal onset
%trialList(:,9)
trialList.RT(:,10) = zeros(p.stimN, 1); %C10: RT
%% Try Loop
%% Set up the Screen
HideCursor;
screen = max(Screen('Screens')); %screen = monitor name
% Set priority
Priority(MaxPriority(screen));
% Set to less verbose output
OrigScreenLevel = Screen('Preference', 'Verbosity', 1);
% Open window
[win, winRect] = Screen('OpenWindow', screen, 0);
% Get the size of the on screen window
[screenXpixels, screenYpixels] = Screen('WindowSize', win);
% Get flip interval
[IFI, nVal, flipSD] = Screen('GetFlipInterval', win, 100, 0.005, 20);
%Alpha Blending
Screen('BlendFunction', win, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
% calculate pixels per degree (ppd), uses script
PPD = visangle2stimsize(1,1,p.scrDist,p.scrWidth,winRect(3));
% Text
Screen('TextSize', win, 30);
Screen('TextFont', win, 'Helvetica');
c = 'center';
%Define CLUT colors
white = WhiteIndex(screen);
black = BlackIndex(screen);
grey = (white/2);
%% Make fixation cross
FixSize = round(p.fixCrossSize * PPD/2)*2; % Calculate the number of pixels in fractions of degree angle
for i = 1:length(p.fixCrossSize)
FixRect(:,1) = CenterRect([0 0 FixSize(i) FixSize(i)], winRect); %This makes a rectangle of the desired size (in the square brackets), positioned based on the size of winRect, which is the wise of the screen/window.
end
%FixColor = [0 0 0; 255 255 255; 0 0 0]; %Color
%ImageRect = CenterRect( [0 0 m m], winRect); %picture positioning
%% TASK CODING
% --- A1. Instructions --- %
Screen(win, 'fillrect', white);
DrawFormattedText(win, 'Taak is aan het laden', c, c, black);
Screen('Flip', win);
% --- A.2 Load in Images as mat/tex --- %
loadJPG_as_Textures; %uses script
% --- A.3 Instructions ---%
DrawFormattedText(win, 'Welkom!', c, 400, [0 153 153]);
DrawFormattedText(win, 'Je gaat een aantal afbeeldingen zien. \n\n Geef zo snel mogelijk aan of je de afbeeldingen negatief, neutraal, of positief vindt.', c, 550, [0 0 255]);
DrawFormattedText(win, 'Voor negatief druk links \n\n Voor neutraal druk onder \n\n Voor positief druk rechts', c, 800, [0 0 255]);
DrawFormattedText(win, 'Druk op een knop om te beginnen!', c, 1000, [0 153 153]);
Screen('Flip', win);
% --- A.4 Participant Ready ---%
%Press any button to begin:
key = 0;
while key == 0
[keyIsDown] = KbCheck; %keep checking if key press till:
if keyIsDown %key is pressed
key = 1;
end
end
% --- A.5 Pull the Trigger --- %
DrawFormattedText(win, 'Wachten op scanner, de taak begint zo!', c, c, black);
Screen('Flip', win);
% Press 5% to start the experiment
while KbCheck, end
while 1
[keyIsDown, ~ , keyCode] = KbCheck;
if keyCode(53); %trigger code = 5% on keyboard, or 84 (=t), test under scanner
break;
end
end
%% Set up pre fixation block and loop
escKey = 27; %esc key code
quitRun = 0;
fixDur = p.fixDur;
runStart = GetSecs; %time experiment started
Date = clock; %clock returns [year month day hour min sec] at startup of trial
Screen('FillRect', win, black);
Screen('FillOval', win, white, FixRect);
Screen('Flip', win);
while (GetSecs-runStart) <= p.prePost; %while time is less then fixation time at beginning of scan, do this
end
%% The Trial Loop - Start the experiment for real now! %%
for trial = 1: ntrials %length(trialList)
key = 0; % reset to 0 at each trial run to check for responses (change in 0 to value)
K = []; % empty array to be filled with responses later
trialStart = GetSecs; %start time of each consecutive trial
trialTime = trialStart - runStart;
trialList.stimOnset(trial,5) = trialTime; %write out trial Time of each trial run
% --- B1. Adjust Fixation Duration --- %
timeDif = abs(trialList.stimOnset(trial,5) - trialList.idealOnset(trial,8)) %absolute difference between real and ideal onset
if trialList.stimOnset(trial,5) > trialList.idealOnset(trial,8) %if real onset is later then ideal, reduse fixation duration (isi)
fixDur = p.fixDur - timeDif;
elseif trialList.stimOnset(trial,5) < trialList.idealOnset(trial,8) %if real onset earlier, add time to fixation duration/isi
fixDur = p.fixDur + timeDif;
end
% --- B2. Present the Stimuli --- %
Screen('FillRect', win, black);
if (trial ~= ntrials) %if this trial isn't last read out images
% Load the stimuli onto screen
Screen('DrawTexture', win, tex(trial_order(trial+1))); %uses loadJPG_as_Texture.m
stim_start(:,1) = GetSecs; %when each stimulus was actually presented
end
%%
save(outputfile);
Screen('CloseAll');
end
Walter Roberson
2019 年 9 月 8 日
theDir = [pwd filesep]; % Returns directory where the script is located (pwd = directory where script is in, filesep = slash that corresponds to your computer system) % cd = theDir
dirStim = [theDir 'stim_encoding' filesep]; % folder with stimuli;
% use filesep instead of / for uniformity
% Filename of outputfile
outputfile = [theDir 'DATA' filesep 'PS_Encoding_S' num2str(subjID) '.mat'];
It is recommended that you use fullfile() instead of constructing paths with filesep yourself.
Guillaume
2019 年 9 月 8 日
None of this is going to help with your error but as Walter said, using fullfile would greatly simplify the start of your code:
dirstim = fullfile(pwd, 'stim_encoding');
outputfile = fullfile(pwd, 'DATA', sprintf('PS_Encoding_S%d.mat'), subjID);
There's also plenty wrong with this block:
%% Make the output list
trialList.SubjID(:,1) = repmat(subjID, 1, p.stimN); %C1: SubjId to be repeated in 1 row for amount of p.stimN
trialList.runNr(:,2) = repmat(runNr, 1, p.stimN); % C2: run Number
trialList.trialNum(:,3) = repmat(1:p.stimN, 1); % C3: write out 1 through last trial Number (1-148)
trialList.trialOrder(:,4) = repmat(trial_order, 1)'; %C4: stim num/order of trials random
% empty counters to be filled in as we move through loop:
trialList.stimOnset(:,5) = zeros(p.stimN, 1); %C5: stim onset
trialList.stimType(:,6) = zeros(p.stimN, 1); %C6: cathegory response/Stimtype
%trialList(:,7) =
trialList.idealOnset(:,8) = p.prePost:p.trialDur:(p.stimN*p.trialDur)+(p.prePost-p.trialDur); %C8: ideal onset
%trialList(:,9)
trialList.RT(:,10) = zeros(p.stimN, 1); %C10: RT
The first line assign to the first column of subjID, the 2nd line to the 2nd column of a completely different variable runNr. The first column of runNr will be filled with 0s and never be used. And so on, RT will have 10 columns, the first 9 filled with 0s and never used.
The repmat are also a bit confusing, the ones that do something create row vectors which are then assigned to column vectors, a bit sloppy, and others are just repmat(x, 1) which are pointless, you just get x. This would be a lot better:
trialList.SubjID = repmat(subjID, p.stimN, 1); %C1: SubjId to be repeated in 1 row for amount of p.stimN
trialList.runNr = repmat(runNr, p.stimN, 1); % C2: run Number
trialList.trialNum = (1:p.stimN)'; % C3: write out 1 through last trial Number (1-148)
trialList.trialOrder = trial_order(:); %C4: stim num/order of trials random
% empty counters to be filled in as we move through loop:
trialList.stimOnset = zeros(p.stimN, 1); %C5: stim onset
trialList.stimType = zeros(p.stimN, 1); %C6: cathegory response/Stimtype
trialList.idealOnset = (0:p.stimN-1)' * p.trialDur + p.prePost; %A simpler way to create your vector
trialList.RT = zeros(p.stimN, 1); %C10: RT
and of course, later when you use the variables, you don't bother with the column index, eg.
timeDif = abs(trialList.stimOnset(trial) - trialList.idealOnset(trial)) %absolute difference between real and ideal onset
Alix
2019 年 9 月 8 日
Thank you both, I got it to work now finally =) just in time.
Enjoy the rest of your weekend!
Guillaume
2019 年 9 月 9 日
As it may be helpful for others to know what the solution was, could you post it as an answer and then accept your own answer?
採用された回答
Alix
2019 年 9 月 10 日
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!
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
アジア太平洋地域
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)
