I have to seperate a list of words into two conditions(each containing 10 words), take 5 words randomly from each condition, and display them. Please help. I've provided the code I have so far.

The problem I am having is being able to put them back together and randomly show five from each condition.
Words=textread( '20highlow.txt' , '%s' , 'delimiter' , '\t' );%opens a txt file
Condition1HF = Words(1:10);
total_wordsHF = (length(Condition1HF)/2)%this is the total number of words
% total_wordsHF = 5
% rand_orderHF = randperm(total_wordsHF)
% listlengthHF=length(rand_orderHF)
% listlengthHF=5
%
% for i = 1: listlengthHF; %displays words
% stimulus = char(Condition1HF(rand_orderHF(i)));%Randomize Words
% char(Condition1HF(i));%; suppresses whole output
% end
Condition2LF = Words(11:20);
total_wordsLF = (length(Condition2LF)/2) %this is the total number of words
% total_wordsLF = 5
% rand_orderLF = randperm(total_wordsLF);
% listlengthLF=length(rand_orderLF);
% listlengthLF=5;
%
% for i = 1: listlengthLF; %displays words
% stimulus2 = char(Condition2LF(rand_orderLF(i)));%Randomize Words
% char(Condition2LF(i));%; suppresses whole output
% end
Conditions = ([Condition1HF ; Condition2LF])
total_words = [total_wordsHF ; total_wordsLF]
rand_order = randperm(total_words)
listlength=length(rand_order)
% total_words = length(Conditions);
% rand_order = randperm(total_words);
% listlength=length(rand_order);
% listlength=10;
for i = 1: listlength; %displays words
set(buttons, 'visible', 'on'); %Turn on Buttons
typing = 0;
press = 0;
stimulus = char(Conditions(rand_order(i)));%Randomize Words
t2= text(.4,.5,stimulus);
axis('off');
set(f1,'color','w')
char(Words(i));%; suppresses whole output
set(gcf,'UserData',0);
while press == 0; %wait for participant to click continue
pause( 0.1 );
typing = get( gcf , 'UserData' );
if typing > 0; %participant has clicked 1
press = 1;
end
end
%pause(1);
delete(t2)
listofresponses(i)=typing;
fprintf(fid, '%s\t%d\t%d\r\n' ,M , i, listofresponses(i));
%listofresponses(i, 2)=PPressed;

Answers (1)

If you want to choose 5 works out of 10 randomly, use this:
Words=cellstr(('a':'j')');
index=randperm(10);
index=index(1:5);
ChosenWords=Words(index)

3 Comments

I am able to do that for instance with the commented code I have above:
Condition1HF = Words(1:10);
total_wordsHF = length(Condition1HF)
rand_orderHF = randperm(total_wordsHF)
listlengthHF=length(rand_orderHF)
listlengthHF=5
but this is just for one condition and I can do it for the other. My problem is putting them back together and having all 10 words (five from each) shown.
Words1={'ab,'b','c'};
Words2={'jfdsa','aksjd'};
AllWords=[Words1,Words2];
The function form of the concatenation is horzcat() or vertcat().

Sign in to comment.

Categories

Find more on Psychology in Help Center and File Exchange

Asked:

on 13 Nov 2011

Community Treasure Hunt

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

Start Hunting!