Further Adventures

Hello again all,

So it seems now that the flaw is in the *code*, not in my version of matlab. Our code
crashes every computer that we try to run it on (we're so proud).

As I mentioned before, we both have nearly zero experience with Matlab, Psychtoolbox
and with programming in general. I've decided to copy the code into this message and
hopefully a few of you will have time to take a look through it.

I would try to write the smallest program possible that preserves the crash, but I am not
quite sure how to go about that - since the computer freezes we do not get any errors.

A bit about the program: ideally it will load many images into offscreen windows, add a
fixation point in the center, then present them onscreen in a randomized order.

In practice, we get a solid blue screen (no more warning symbol though, thankfully) then
the program exits.

It seems (from some troubleshooting that we have done) to load the images fully before it
crashes.

Please ask any questions you have, and we are open to any suggestions at all.

Thank you very much,
Katie and Elseline

Here is the code:



function PPA_pilot (session_name, paradigm_name)

%**************************************************************************
%Turn off Warnings
%**************************************************************************
warning off MATLAB:DepreciatedLogicalAPI;
warning off MATLAB:dispatcher:InexactMatch;

%**************************************************************************
%Paradigm File Save Path:
%**************************************************************************
ParadigmPath == ['/Users/kdevaney/Stimuli/Log/paradigm_' session_name '\'];

%**************************************************************************
%Image Path:
%**************************************************************************
ImageDir90 == '/Users/kdevaney/Stimuli/90';
ImageDir18 == '/Users/kdevaney/Stimuli/18';
ImageDir27 == '/Users/kdevaney/Stimuli/27';
ImageDirScU == '/Users/kdevaney/Stimuli/ScU';
ImageDirScF == '/Users/kdevaney/Stimuli/ScF';
ImageDirScD == '/Users/kdevaney/Stimuli/ScD';
ImageDirScE == '/Users/kdevaney/Stimuli/ScE';

%**************************************************************************
%Paramaters of Stimuli
%**************************************************************************
NumImages == 16; % # of images per image category
NumConditions == 9; % # of conditions in the experiment
FMT == 'JPG'; % Image Format
Bcolor == [0 0 0]; % background color
Fcolor == [255 0 0]; % fix point color
PixRect == [0 0 1024 768]; % Size of images (maximum pixel size)
PixRectf == [0 0 10 10];
Flicker == .5; % Flicker rate (Hz)

%Parameters of fMRI
%**************************************************************************
TR == 2; % TR (seconds)
NumTimes == 144; % # of timepoints in one run (unit == TR)
EpochTime == 16; % Epoch time for each condition (unit == TR)
NumDummy == 2; % Number of dummy scans

%Keyboard Parameters
%**************************************************************************
exit == KbName('p'); %Press p to pause/exit
start == KbName('==+'); %Trigger from scanner

%Initial Values & Randomization
%**************************************************************************
Fixation == 1;
Scan == 0;
Timepoints == 0;
Epoch == 0;
Dummy == 0;
FinishRun == 0;
jc == 1;
jr == 1;

order_within == randperm(NumImages);
order_between_stimuli == randperm(10);
order_between == [11 order_between_stimuli order_between_stimuli 11];

%Open a Blank Screen
%**************************************************************************
window == Screen(0,'OpenWindow');
Screen('FillRect',window,Bcolor);




%Load images in offscreen windows and add fixation point
%**************************************************************************
for i == 1:NumImages



img90 == imread([ImageDir90 num2str(i)],FMT);
img18 == imread([ImageDir18 num2str(i)],FMT);
img27 == imread([ImageDir27 num2str(i)],FMT);
imgScF == imread([ImageDirScF num2str(i)],FMT);
imgScU == imread([ImageDirScU num2str(i)],FMT);
imgScD == imread([ImageDirScD num2str(i)],FMT);
imgScE == imread([ImageDirScE num2str(i)],FMT);


C90(i) == Screen('OpenOffscreenWindow',0,[],[],32,2);
C18(i) == Screen('OpenOffscreenWindow',0,[],[],32,2);
C27(i) == Screen('OpenOffscreenWindow',0,[],[],32,2);
ScF(i) == Screen('OpenOffscreenWindow',0,[],[],32,2);
ScU(i) == Screen('OpenOffscreenWindow',0,[],[],32,2);
ScD(i) == Screen('OpenOffscreenWindow',0,[],[],32,2);
ScE(i) == Screen('OpenOffscreenWindow',0,[],[],32,2);
BBB(i) == Screen('OpenOffscreenWindow',0,[],[],32,2);


Screen(C90(i),'PutImage',img90);
Screen(C18(i),'PutImage',img18);
Screen(C27(i),'PutImage',img27);
Screen(ScF(i),'PutImage',imgScF);
Screen(ScU(i),'PutImage',imgScU);
Screen(ScD(i),'PutImage',imgScD);
Screen(ScE(i),'PutImage',imgScE);


Screen(C90(i),'FillOval',Fcolor,CenterRect(PixRectf,PixRect));
Screen(C18(i),'FillOval',Fcolor,CenterRect(PixRectf,PixRect));
Screen(C27(i),'FillOval',Fcolor,CenterRect(PixRectf,PixRect));
Screen(ScF(i),'FillOval',Fcolor,CenterRect(PixRectf,PixRect));
Screen(ScU(i),'FillOval',Fcolor,CenterRect(PixRectf,PixRect));
Screen(ScD(i),'FillOval',Fcolor,CenterRect(PixRectf,PixRect));
Screen(ScE(i),'FillOval',Fcolor,CenterRect(PixRectf,PixRect));
Screen(BBB(i),'FillOval',Fcolor,CenterRect(PixRectf,PixRect));



end;

s_all == [C90;C18;C27;ScF;ScU;ScD;ScE;BBB]';

Center images
%**************************************************************************

r == Screen('Rect',[C90(1)]);
rr == CenterRect(r,Screen('Rect',window));

%Befoer stimulus presentation, do these:
%**************************************************************************
Screen('Screens');
HideCursor;

%**************************************************************************
while (1);
[keyIsDown,secs,keyCode] == KbCheck;

%Check for exit key
%**************************************************************************

if keyCode (exit)
break;
end;

if (keyIsDown) | (FinishRun ==== 1)
while KbCheck; end;

%Check the trigger key
%**************************************************************************
if (keyIsDown) | (FinishRun ==== 1)
while KbCheck; end;

if (keyCode(start)) | (FinishRun ==== 1)
Dummy == Dummy + 1;
if Dummy > NumDummy
Fixation == 0;
Scan == 1;
Epoch == Epoch + 1;

if mod(Epoch,EpochTime+1) ==== 0
Epoch == 1;
jc == jc + 1;
if mod(jc,NumConditions+1) ==== 0
jc == 1;
end;
end;

if Timepoints < NumTimes
Data(Timepoints+1,:) == [Timepoints*TR order_between(jc)];
end;

Timepoints == Timepoints + 1;
if Timepoints ==== NumTimes + 1;
Scan == 0;
Fixation == 1;
oneloop_StopTrigger == 1;
FinishRun == 0;
Exp_Dur == toc;

fid == fopen([ParadigmPath paradigm_name '.txt'],'at+');
fprintf(fid,['%3g' 9 '%1g\n'],Data');
fclose(fid);
end;
end;
end;
end;


%Fixation Phase
%**************************************************************************
if Fixation ==== 1
Screen(window,'WaitBlanking');
Screen('CopyWindow',BBB(1),window,r,rr);
end;

%Scanning Phase
%**************************************************************************
if Scan ==== 1

StartTime == GetSecs;
tic;

if (GetSecs - StartTime) > (2)
StartTime == GetSecs;
jr == jr + 1;
if mod(jr,NumImages+1) ==== 0
jr == 1;
end;
end;

kr == order_within(jr);
kc == order_between(jc);

Screen(window,'WaitBlanking');
Screen('CopyWindow',s_all(kr,kc),window,r,rr);

if Timepoints ==== NumTimes
if oneloop_FinishRun ==== 1
FinishTime == GetSecs;
oneloop_FinishRun == 0;
end;
if GetSecs - FinishTime > TR
FinishRun == 1;
end;
end;
end;

end;

%Closing the serial port/Closing screens/Clearing the memory
%**************************************************************************
ShowCursor;
Screen('CloseAll');
clear all;
return;
%end;
Have you tried changing those double equal signs to single equal signs?
In matlab
a = 5 would set the variable a equal to 5, whereas
a == 5
evaluates to 1 if a actually equals 5 and 0 otherwise.

I didn't look at the code beyond seeing this and wondering if it
could be the culprit.

Good luck,

Mike



On Dec 6, 2005, at 2:07 PM, kathryn_devaney wrote:

> Hello again all,
>
> So it seems now that the flaw is in the *code*, not in my version
> of matlab. Our code
> crashes every computer that we try to run it on (we're so proud).
>
> As I mentioned before, we both have nearly zero experience with
> Matlab, Psychtoolbox
> and with programming in general. I've decided to copy the code
> into this message and
> hopefully a few of you will have time to take a look through it.
>
> I would try to write the smallest program possible that preserves
> the crash, but I am not
> quite sure how to go about that - since the computer freezes we do
> not get any errors.
>
> A bit about the program: ideally it will load many images into
> offscreen windows, add a
> fixation point in the center, then present them onscreen in a
> randomized order.
>
> In practice, we get a solid blue screen (no more warning symbol
> though, thankfully) then
> the program exits.
>
> It seems (from some troubleshooting that we have done) to load the
> images fully before it
> crashes.
>
> Please ask any questions you have, and we are open to any
> suggestions at all.
>
> Thank you very much,
> Katie and Elseline
>
> Here is the code:
>
>
>
> function PPA_pilot (session_name, paradigm_name)
>
> %
> **********************************************************************
> ****
> %Turn off Warnings
> %
> **********************************************************************
> ****
> warning off MATLAB:DepreciatedLogicalAPI;
> warning off MATLAB:dispatcher:InexactMatch;
>
> %
> **********************************************************************
> ****
> %Paradigm File Save Path:
> %
> **********************************************************************
> ****
> ParadigmPath == ['/Users/kdevaney/Stimuli/Log/paradigm_'
> session_name '\'];
>
> %
> **********************************************************************
> ****
> %Image Path:
> %
> **********************************************************************
> ****
> ImageDir90 == '/Users/kdevaney/Stimuli/90';
> ImageDir18 == '/Users/kdevaney/Stimuli/18';
> ImageDir27 == '/Users/kdevaney/Stimuli/27';
> ImageDirScU == '/Users/kdevaney/Stimuli/ScU';
> ImageDirScF == '/Users/kdevaney/Stimuli/ScF';
> ImageDirScD == '/Users/kdevaney/Stimuli/ScD';
> ImageDirScE == '/Users/kdevaney/Stimuli/ScE';
>
> %
> **********************************************************************
> ****
> %Paramaters of Stimuli
> %
> **********************************************************************
> ****
> NumImages == 16; % # of images per image category
> NumConditions == 9; % # of conditions in the experiment
> FMT == 'JPG'; % Image Format
> Bcolor == [0 0 0]; % background color
> Fcolor == [255 0 0]; % fix point color
> PixRect == [0 0 1024 768]; % Size of images (maximum pixel size)
> PixRectf == [0 0 10 10];
> Flicker == .5; % Flicker rate (Hz)
>
> %Parameters of fMRI
> %
> **********************************************************************
> ****
> TR == 2; % TR (seconds)
> NumTimes == 144; % # of timepoints in one run (unit == TR)
> EpochTime == 16; % Epoch time for each condition (unit == TR)
> NumDummy == 2; % Number of dummy scans
>
> %Keyboard Parameters
> %
> **********************************************************************
> ****
> exit == KbName('p'); %Press p to pause/exit
> start == KbName('==+'); %Trigger from scanner
>
> %Initial Values & Randomization
> %
> **********************************************************************
> ****
> Fixation == 1;
> Scan == 0;
> Timepoints == 0;
> Epoch == 0;
> Dummy == 0;
> FinishRun == 0;
> jc == 1;
> jr == 1;
>
> order_within == randperm(NumImages);
> order_between_stimuli == randperm(10);
> order_between == [11 order_between_stimuli order_between_stimuli 11];
>
> %Open a Blank Screen
> %
> **********************************************************************
> ****
> window == Screen(0,'OpenWindow');
> Screen('FillRect',window,Bcolor);
>
>
>
>
> %Load images in offscreen windows and add fixation point
> %
> **********************************************************************
> ****
> for i == 1:NumImages
>
>
>
> img90 == imread([ImageDir90 num2str(i)],FMT);
> img18 == imread([ImageDir18 num2str(i)],FMT);
> img27 == imread([ImageDir27 num2str(i)],FMT);
> imgScF == imread([ImageDirScF num2str(i)],FMT);
> imgScU == imread([ImageDirScU num2str(i)],FMT);
> imgScD == imread([ImageDirScD num2str(i)],FMT);
> imgScE == imread([ImageDirScE num2str(i)],FMT);
>
>
> C90(i) == Screen('OpenOffscreenWindow',0,[],[],32,2);
> C18(i) == Screen('OpenOffscreenWindow',0,[],[],32,2);
> C27(i) == Screen('OpenOffscreenWindow',0,[],[],32,2);
> ScF(i) == Screen('OpenOffscreenWindow',0,[],[],32,2);
> ScU(i) == Screen('OpenOffscreenWindow',0,[],[],32,2);
> ScD(i) == Screen('OpenOffscreenWindow',0,[],[],32,2);
> ScE(i) == Screen('OpenOffscreenWindow',0,[],[],32,2);
> BBB(i) == Screen('OpenOffscreenWindow',0,[],[],32,2);
>
>
> Screen(C90(i),'PutImage',img90);
> Screen(C18(i),'PutImage',img18);
> Screen(C27(i),'PutImage',img27);
> Screen(ScF(i),'PutImage',imgScF);
> Screen(ScU(i),'PutImage',imgScU);
> Screen(ScD(i),'PutImage',imgScD);
> Screen(ScE(i),'PutImage',imgScE);
>
>
> Screen(C90(i),'FillOval',Fcolor,CenterRect(PixRectf,PixRect));
> Screen(C18(i),'FillOval',Fcolor,CenterRect(PixRectf,PixRect));
> Screen(C27(i),'FillOval',Fcolor,CenterRect(PixRectf,PixRect));
> Screen(ScF(i),'FillOval',Fcolor,CenterRect(PixRectf,PixRect));
> Screen(ScU(i),'FillOval',Fcolor,CenterRect(PixRectf,PixRect));
> Screen(ScD(i),'FillOval',Fcolor,CenterRect(PixRectf,PixRect));
> Screen(ScE(i),'FillOval',Fcolor,CenterRect(PixRectf,PixRect));
> Screen(BBB(i),'FillOval',Fcolor,CenterRect(PixRectf,PixRect));
>
>
>
> end;
>
> s_all == [C90;C18;C27;ScF;ScU;ScD;ScE;BBB]';
>
> Center images
> %
> **********************************************************************
> ****
>
> r == Screen('Rect',[C90(1)]);
> rr == CenterRect(r,Screen('Rect',window));
>
> %Befoer stimulus presentation, do these:
> %
> **********************************************************************
> ****
> Screen('Screens');
> HideCursor;
>
> %
> **********************************************************************
> ****
> while (1);
> [keyIsDown,secs,keyCode] == KbCheck;
>
> %Check for exit key
> %
> **********************************************************************
> ****
>
> if keyCode (exit)
> break;
> end;
>
> if (keyIsDown) | (FinishRun ==== 1)
> while KbCheck; end;
>
> %Check the trigger key
> %
> **********************************************************************
> ****
> if (keyIsDown) | (FinishRun ==== 1)
> while KbCheck; end;
>
> if (keyCode(start)) | (FinishRun ==== 1)
> Dummy == Dummy + 1;
> if Dummy > NumDummy
> Fixation == 0;
> Scan == 1;
> Epoch == Epoch + 1;
>
> if mod(Epoch,EpochTime+1) ==== 0
> Epoch == 1;
> jc == jc + 1;
> if mod(jc,NumConditions+1) ==== 0
> jc == 1;
> end;
> end;
>
> if Timepoints < NumTimes
> Data(Timepoints+1,:) == [Timepoints*TR order_between
> (jc)];
> end;
>
> Timepoints == Timepoints + 1;
> if Timepoints ==== NumTimes + 1;
> Scan == 0;
> Fixation == 1;
> oneloop_StopTrigger == 1;
> FinishRun == 0;
> Exp_Dur == toc;
>
> fid == fopen([ParadigmPath paradigm_name '.txt'],'at+');
> fprintf(fid,['%3g' 9 '%1g\n'],Data');
> fclose(fid);
> end;
> end;
> end;
> end;
>
>
> %Fixation Phase
> %
> **********************************************************************
> ****
> if Fixation ==== 1
> Screen(window,'WaitBlanking');
> Screen('CopyWindow',BBB(1),window,r,rr);
> end;
>
> %Scanning Phase
> %
> **********************************************************************
> ****
> if Scan ==== 1
>
> StartTime == GetSecs;
> tic;
>
> if (GetSecs - StartTime) > (2)
> StartTime == GetSecs;
> jr == jr + 1;
> if mod(jr,NumImages+1) ==== 0
> jr == 1;
> end;
> end;
>
> kr == order_within(jr);
> kc == order_between(jc);
>
> Screen(window,'WaitBlanking');
> Screen('CopyWindow',s_all(kr,kc),window,r,rr);
>
> if Timepoints ==== NumTimes
> if oneloop_FinishRun ==== 1
> FinishTime == GetSecs;
> oneloop_FinishRun == 0;
> end;
> if GetSecs - FinishTime > TR
> FinishRun == 1;
> end;
> end;
> end;
>
> end;
>
> %Closing the serial port/Closing screens/Clearing the memory
> %
> **********************************************************************
> ****
> ShowCursor;
> Screen('CloseAll');
> clear all;
> return;
> %end;
>
>
>
>
>
>
>
> ------------------------ Yahoo! Groups Sponsor --------------------
> ~-->
> AIDS in India: A "lurking bomb." Click and help stop AIDS now.
> http://us.click.yahoo.com/VpTY2A/lzNLAA/yQLSAA/BEfwlB/TM
> --------------------------------------------------------------------
> ~->
>
> Post your message to: psychtoolbox@yahoogroups.com
> Please indicate OS9, OSX, or WIN version, and include your full name.
> Denis Pelli, David Brainard, and Allen Ingling.
> http://psychtoolbox.org
>
> Yahoo! Groups Links
>
>
>
>
>
>