Hi,
a) how do create a stroop test to randomise the colour of the word. e.g. the word 'RED' with a blue/green/white font colour
b) i am also interested in randomising the colour of a square
i have the codes to display the word and the 2 squares below it but how do i get it to run with varying colours throughout the experiment in a randomised order?
any help would be much appreciated and many thanks in advance

 Accepted Answer

Adam Danz
Adam Danz on 6 Dec 2019
Edited: Adam Danz on 6 Dec 2019
The handle to the text object and the handle to the "square" (not sure what you mean here, it could be a rectangle object, a patch object, an axes, who knows...) both have properties that allow you to edit their colors. But the property names vary between different sets of objects. Since we don't know what kind of objects you're working with, we can only be as specific as the content offered in your question (which isn't specific).
The two most common property names that changes an object's color are
  • Color
  • FaceColor
This demo below shows you how to change the "Color" property. The "FaceColor" property of other objects works in the same way.
h = text(. . .);
h.Color = 'r';
% -or-
h.Color = [1 0 0];
% -or-
set(h, 'Color', [1 0 0])

9 Comments

Hi, I created the squares using the cgrect function
this is the code i used to get the word at the top of the screen with the 2 squares below it. the word was set by using cgtext and the squares using cgrect
config_display(0,1, [0 0 0], [1 1 1], 'calibri', 22,6);
start_cogent
cgloadlib;
warning('off','MATLAB:nargchk:deprecated')
cgscale(40)
cgpencol(1,0,0)
cgrect(-8,-4,7,7)
cgpencol(0,0,1)
cgrect(8,-4,7,7)
cgpencol(0,0,1)
cgfont('calibri',8)
cgtext('RED',0,10)
cgflip
wait(3000)
i want to know how i can randomise the word, the colour of the word and the colour of the squares
many thanks
I don't have that library but I found the user manual and briefly looked up the function you're using.
These function appear to be wrapper functions to Matlab's text() and rectangle() functions. It wasn't clear in my 3-minutes of looking at the manual whether those functions have outputs that provide you with the object handle. If they do, you can use the same approach as in my answer.
i used he manual to get these codes, i have also created a matrix containing a 9x2 structure.
the first column for the word of the colour and the 2nd to represent the colour of the word. I intend on duplicating the matrix multiple times and randomising the order. Im just stuck on how i can ensure the number representatives are linked to the actual code for the colour.
e.g. red is represented as - cgpencol(1,0,0)
and in my matrix red is represented as 1, blue as 2 and green as 3
so would i have to create aTable to distringuish the 2 rows from each other e.g. column(words) and column 2(colourofword)?
then
words(1 2 3)= [red;blue;green]
colourofwords(1 2 3)= [1 0 0;0 0 1;0 1 0]
so that the numbers in column 1 have a different representation to column 2
e.g. 1
column 1 is red
column 2 is [1 0 0]
Adam Danz
Adam Danz on 6 Dec 2019
Edited: Adam Danz on 6 Dec 2019
Now your question is better defined but I'm still not 100% certain about what you want to do but I'll give it a shot (again).
See the inline comments for details.
% Create a 'key' table that defines the conditions.
K = table([1;2;3],{'red';'blue';'green'},[1 0 0; 0 0 1; 0 1 0],...
'VariableNames',{'index','colorWord','Color'});
% K =
% 3×3 table
% index colorWord Color
% _____ _________ ___________
% 1 'red' 1 0 0
% 2 'blue' 0 0 1
% 3 'green' 0 1 0
% Create n randomized colorWord / Color pairs
n = 10;
randIdx = randi(max(K.index),n,2); % randomized row selection
conditions = table(K.colorWord(randIdx(:,1)), K.Color(randIdx(:,2),:), ...
'VariableNames',{'colorWord','Color'});
% conditions =
% 10×2 table
% colorWord Color
% _________ ___________
% 'red' 1 0 0
% 'red' 0 0 1
% 'green' 0 0 1
% 'green' 0 1 0
% 'green' 1 0 0
% 'green' 0 0 1
% 'green' 0 0 1
% 'red' 0 0 1
% 'blue' 0 1 0
% 'blue' 0 0 1
To access condition number 4 (for example),
a = conditions.colorWord(4);
b = conditions.Color(4,:);
Hi thanks for all the help,
I did
a = conditions.colorWord(1:45); to get the 45 WordColors
but when i did
b = conditions.Color(2:45); it didnt give me the 3 columns for color. instead it showed 1 line vertically instead of it being horizontal9 as it was shown in Conditions.
I tried doing
b = conditions.Color(1:45,2:45,3:45); but that didnt work, also tried with just (1:45). it only semi worked and showed the 2nd column for Color when i did b = conditions.Color(1:45,2:45,3); by accident. How do i get the whole of Color e.g.
1 0 0
0 0 1
0 0 1
0 1 0
1 0 0
0 0 1
0 0 1
0 0 1
0 1 0
0 0 1
to be in b using the b = conditions.Color(4,:); example.
Also, once the wordColour and Colour have been placed in A and B, will i be able to incorprorate them into a loop? so that the words in the stroop test are in a random order and with randomised colour font?
Look at the example more closely.
b = conditions.Color(2:45,:);
thanks for the help, its been fixed now i did b = conditions.Color(1:45,:); and all the 45 colour codes were put into b
I am also trying to create a loop for presenting the stroop words
  • i know that A(word) and B(colour) now have a randomised order. i am now trying to incorproate that into a for loop.
How do i do this,
i went on the cogent website and this is the xample they gave for a stroop loop but i dont understand it, can you please help me explain what it means?
Here's a general template to show how to set up a loop. I don't know what loop you want to make but you can follow this plan:
for i = 1:size(conditions ,1)
% access the i_th condition
condition.colorWord(i)
condition.Color(i)
end
About the content on the cogent website, there are comments on each line of the code that tells you what the lines are doing. If you have a question about a specific line and cannot understand the help() and doc() literature, tell me which line to help you out with.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!