How to randomize code run in RUSH

Hi folks,

I'm having a problem getting RUSH to recognize code as executable,
rather than the
contents of a variable.

I have a routine that randomly selects one of five cell arrays, each
with a set of strings in it
that is the label to a binary .mat file that contains the code.
After one of the five arrays is
selected, one of the cells is randomly selected, and this string is
then set into the contents
of a variable. I then use the LOAD command to load that .mat file
into the workspace.

My problem is that RUSH needs to have the name of this .mat variable,
and it must be a
string that specifies a character array. I can specify the variable
that contains the name of
the .mat file as the first argument to RUSH, but I can't get my
script to perform the cell to
character conversion for that .mat file... config = char(config);
doesn't work in my script,
while it does work in the command window interactively.

If anyone has any suggestions about how to resolve this, or
suggestions for alternative
methods for specifying the code to be run by RUSH, I'd appreciate it.
This has got me
stumped...
--- In psychtoolbox@yahoogroups.com, "mogwaisc" <mogwaisc@y...>
wrote:
> This is a clarification of my earlier post.
>
> I have a routine that randomly selects the name of a
> .mat file which holds a block of code to be executed
> by RUSH. This gives me a character array such as:
>
> config = Q1T03C15 (1x8 character array)
>
> I then use LOAD to load this variable into the workspace.
> It contains code to be executed by RUSH.
>
> Then I specify RUSH to call this variable:
>
> Rush(config, 1);
>
> But, the code is not executed. Instead, the contents of the
> variable are displayed in the command window:
>
> Q1T03C15 =
> 'window1 = Screen(0, 'OpenWindow', 0, [], 8);'
> 'Screen(window1, 'SetClut', clut8, [], 8);'
> 'Screen(window1, 'TextFont', FontName);'
> 'Screen(window1, 'TextSize', FontSize);'
> 'window2 = Screen(0, 'OpenOffscreenWindow', 0, [], 8);'
> 'Screen(window2, 'SetClut', clut8, [], 8);'
> 'Screen(window2, 'TextFont', FontName);'
> 'Screen(window2, 'TextSize', FontSize);'
> 'Ask(window1, beginstring, 255, 0, 'KbWait');'
> 'secs1 = KbWait;'
> 'Screen(window1, 'WaitBlanking', x1);'
> 'Screen(window2, 'DrawText', '+', 576, 432, 255);'
> 'Screen('CopyWindow', window2, window1);'
> 'secs2 = GetSecs;'
> 'Screen(window1, 'WaitBlanking', x2);'
> 'Screen(window2, 'FillRect', 0);'
> 'Screen('CopyWindow', window2, window1);'
> 'secs3 = GetSecs;'
> 'Screen(window2, 'DrawText', distractor, 906, 162, 255);'
> 'Screen(window2, 'DrawText', distractor, 876, 110, 255);'
> 'Screen(window2, 'DrawText', distractor, 816, 110, 255);'
> 'Screen(window2, 'DrawText', distractor, 786, 162, 255);'
> 'Screen(window2, 'DrawText', distractor, 816, 214, 255);'
> 'Screen(window2, 'DrawText', distractor, 876, 214, 255);'
> 'Screen(window2, 'DrawText', distractor, 867, 141, 255);'
> 'Screen(window2, 'DrawText', target, 825, 141, 255);'
> 'Screen(window2, 'DrawText', distractor, 825, 183, 255);'
> 'Screen(window2, 'DrawText', distractor, 867, 183, 255);'
> 'Screen(window2, 'DrawText', distractor, 396, 162, 255);'
> 'Screen(window2, 'DrawText', distractor, 384, 117, 255);'
> 'Screen(window2, 'DrawText', distractor, 351, 84, 255);'
> 'Screen(window2, 'DrawText', distractor, 306, 72, 255);'
> 'Screen(window2, 'DrawText', distractor, 261, 84, 255);'
> 'Screen(window2, 'DrawText', distractor, 228, 117, 255);'
> 'Screen(window2, 'DrawText', distractor, 216, 162, 255);'
> 'Screen(window2, 'DrawText', distractor, 228, 207, 255);'
> 'Screen(window2, 'DrawText', distractor, 261, 240, 255);'
> 'Screen(window2, 'DrawText', distractor, 306, 252, 255);'
> 'Screen(window2, 'DrawText', distractor, 351, 240, 255);'
> 'Screen(window2, 'DrawText', distractor, 384, 207, 255);'
> 'Screen(window2, 'DrawText', distractor, 336, 132, 255);'
> 'Screen(window2, 'DrawText', distractor, 276, 132, 255);'
> 'Screen(window2, 'DrawText', distractor, 276, 192, 255);'
> 'Screen(window2, 'DrawText', distractor, 336, 192, 255);'
> 'Screen(window2, 'DrawText', distractor, 366, 702, 255);'
> 'Screen(window2, 'DrawText', distractor, 358, 672, 255);'
> 'Screen(window2, 'DrawText', distractor, 336, 650, 255);'
> 'Screen(window2, 'DrawText', distractor, 306, 642, 255);'
> 'Screen(window2, 'DrawText', distractor, 276, 650, 255);'
> 'Screen(window2, 'DrawText', distractor, 254, 672, 255);'
> 'Screen(window2, 'DrawText', distractor, 246, 702, 255);'
> 'Screen(window2, 'DrawText', distractor, 254, 732, 255);'
> 'Screen(window2, 'DrawText', distractor, 276, 754, 255);'
> 'Screen(window2, 'DrawText', distractor, 306, 762, 255);'
> 'Screen(window2, 'DrawText', distractor, 336, 754, 255);'
> 'Screen(window2, 'DrawText', distractor, 358, 732, 255);'
> 'Screen(window2, 'DrawText', distractor, 327, 681, 255);'
> 'Screen(window2, 'DrawText', distractor, 285, 681, 255);'
> 'Screen(window2, 'DrawText', distractor, 285, 723, 255);'
> 'Screen(window2, 'DrawText', distractor, 327, 723, 255);'
> 'Screen(window2, 'DrawText', distractor, 924, 657, 255);'
> 'Screen(window2, 'DrawText', distractor, 846, 612, 255);'
> 'Screen(window2, 'DrawText', distractor, 768, 657, 255);'
> 'Screen(window2, 'DrawText', distractor, 768, 747, 255);'
> 'Screen(window2, 'DrawText', distractor, 846, 792, 255);'
> 'Screen(window2, 'DrawText', distractor, 924, 747, 255);'
> 'Screen(window2, 'DrawText', distractor, 876, 672, 255);'
> 'Screen(window2, 'DrawText', distractor, 816, 672, 255);'
> 'Screen(window2, 'DrawText', distractor, 816, 732, 255);'
> 'Screen(window2, 'DrawText', distractor, 876, 732, 255);'
> 'Screen('CopyWindow', window2, window1);'
> 'secs4 = KbWait;'
> 'Screen(window2, 'FillRect', 0);'
> 'Screen('CopyWindow', window2, window1);'
> 'Screen('CloseAll');'
>
> (This is a 75x1 cell array).
>
> Can anyone tell me why Rush is displaying the contents of this
variable,
> rather than executing the code?
>
> I thought that it might be because it's a cell array, and
> not a character array. However, this occurs even when the variable
> is a character array.
>
> Any help would be appreciated. I'm stumped by this and don't
> know where to go from here.
>
> Thanks in advance,
>
> Paul Thiem,
> UC Santa Cruz.

Did you surround each line with apostrophes and each text command
inside in 2 apostrophes?
SCREEN(window,'FillRect', 127);

becomes...

'SCREEN(window,''FillRect'', 127);'
--- In psychtoolbox@yahoogroups.com, "surf3010" <surf3010@y...> wrote:
> Did you surround each line with apostrophes and each text command
> inside in 2 apostrophes?
> SCREEN(window,'FillRect', 127);
>
> becomes...
>
> 'SCREEN(window,''FillRect'', 127);'

No, the issue wasn't the syntax. I did some extensive testing with
some very simple
scripts using RUSH and my code and the issue is that RUSH cannot
accept a variable, even
one containing a string, as its input argument.

I was able to work around by writing a lengthy IF/IFELSE structure
that specifically declared
every stimulus configuration I use in my experiment. (I also tried a
SWITCH/CASE
structure, but it didn't work with RUSH.) By specifying a string
directly as the argument to
RUSH, rather than trying to use a variable containing a string, the
problem was resolved,
though this added several hundred repetitive lines to my program. I
hope that future
versions of the PTB would take this into consideration, so that RUSH
can take a variable
that holds a string as its argument, rather than being limited to a
string specified directly
in the call to RUSH.
Have you actually tested this routine? Frankly, I don't have time to
myself since I already have my program working and need to move on to
other aspects of my research.

I'm wondering if it does since RUSH itself calls EVAL so I'm kind of
doubtful.

I've written a very simple script to test RUSH where the only
difference is where the name of the code for RUSH was held in a string
variable and that variable specified as the argument to RUSH, as
opposed to specifically naming that code in RUSH. In the former case
RUSH failed to work, where as in the latter case it worked. My method
is much simpler and RUSH broke with it.

I appreciate the advice; at some point when I have the time I might
try it, but I'm doubtful.

--- In psychtoolbox@yahoogroups.com, "franswcornelissen"
<f.w.cornelissen@m...> wrote:
> I
> > hope that future
> > versions of the PTB would take this into consideration, so that RUSH
> > can take a variable
> > that holds a string as its argument, rather than being limited to a
> > string specified directly
> > in the call to RUSH.
>
> you should be able to achieve this using matlab's eval (uate)
> command
>
> % rush-test
>
> fprintf('demo: variable holds name of cell array with bits of code\n');
> mybitofcode={'for i=1:10;'
> 'fprintf(''hello world\n'');'
> 'end;'
> };
>
> myvar='mybitofcode';
>
> myrushstring=['rush(' myvar ',1);']
>
>
> eval(myrushstring,1);
>
> myfile='myrushcode';
>
> % note that in this way you could have multiple variables that hold code
> % and that could be called by changing myvar
>
> fprintf('demo 2: variable with bits of code loaded from .mat file\n');
> % you could achieve something similar using different .mat files:
>
> fprintf('saving variable with code to file ''%s''\n', myfile);
>
>
> save(myfile, 'mybitofcode');
>
> fprintf('clearing variable that holds code\n');
>
> clear mybitofcode % not necessary of course, just to demonstrate the
point
> who % verify its no longer there ;-)
> fprintf('loading variable that holds code to rush from ''%s''\n',
myfile);
>
> load( myfile);
>
> fprintf('rushing it\n');
> rush(mybitofcode,1);
>
> % note that in this way you could have multiple bits of code
> % in different matfiles and that could be called by changing the file
> % from which to load the code (as long as they contain the variable
'mybitofcode'
>
>
>
> Gr.
> Frans