Need programming help
Info
This question is closed. Reopen it to edit or answer.
Show older comments
Trying to 'randomly pick a word' by using Matlab. I set up a column with numerical values 1-4, then I chose a random number generator to pick a number. But now, (the part I need help with) I am trying to set the numerical value to a word associated with the number, I am new at this; please help if you can.
k=0;
cols=['WORD'];
WORD=0;
for i=1
for j=1:4
k=k+1;
word(j,i)=k;
used(j,i)=0;
end
end
count=0;
gameplay=1;
while gameplay
pick=0;
while pick==0
pick_word=ceil(rand()*4);
wordplayed=word(pick_word);
if pick_word==1
wo=disp('skate');
elseif pick_word==2
wo=disp('place');
elseif pick_word==3
wo=disp('sleep');
elseif pick_work==4
wo=disp('lefty');
end
if used(pick_word)==0
used(pick_word)=wordplayed;
pick=1;
count=count+1;
end
end
if pick_word==1
WORD=WORD+1;
end
end
Answers (2)
David Young
on 13 Nov 2011
Instead of
wo = disp('skate');
you need
wo = 'skate';
You're mixing up the process of printing something in a window (which is what the disp function does) with a assigning a value to a variable.
I think you may have some other misconceptions too - for example "I am trying to set the numerical value to a word" doesn't make sense - and I think it would be a good investment of time to go over the "getting started" material in the documentation again.
1 Comment
JG
on 16 Nov 2011
Walter Roberson
on 16 Nov 2011
W = {'skate','place','sleep','lefty'};
r = randperm(length(W));
W(r)
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!