random assignment of color in string

Hello everyone! 

Does anyone know how I can assign one of two colors in every letter of a list randomly?

For example I have:


letters = 'ABCDE'

NLetters = length(letters);

    for j = 1: NLetters %4 grammata K 1 stoxos ara 5 fores 8a kanei auto pou leei katw 

        a = letters(j); %gets a letter from the random order

      

        DrawFormattedText(window, a, x1, y1, ...

            [1 0 0]); 

        t0 = Screen( 'Flip' , window, t0 + blankDur);% letter on

        t0 = Screen( 'Flip' , window, t0 + stimDur);% letter of

    end



This code presents all the letters ABCDE, one after the other in red color. But I want every letter to have a random color, either red or blue. How could I do that?


Thanks on advance!


If rand
Clr = [0 0 1]
Else
Clr = [1 0 0]
End

Then use clr in the drawformattedtext. You need to fix the capitals here, im writing on my phone.

Best,
Dee

On Oct 17, 2017 2:39 AM, "mkoutromanoy@... [PSYCHTOOLBOX]" <PSYCHTOOLBOX@yahoogroups.com> wrote:


Hello everyone!

Does anyone know how I can assign one of two colors in every letter of a list randomly?

For example I have:


letters = 'ABCDE'

NLetters = length(letters);

for j = 1: NLetters %4 grammata K 1 stoxos ara 5 fores 8a kanei auto pou leei katw

a = letters(j); %gets a letter from the random order

DrawFormattedText(window, a, x1, y1, ...

[1 0 0]);

t0 = Screen( 'Flip' , window, t0 + blankDur);% letter on

t0 = Screen( 'Flip' , window, t0 + stimDur);% letter of

end



This code presents all the letters ABCDE, one after the other in red color. But I want every letter to have a random color, either red or blue. How could I do that?


Thanks on advance!