Need programming help
情報
この質問は閉じられています。 編集または回答するには再度開いてください。
古いコメントを表示
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
0 件のコメント
回答 (2 件)
David Young
2011 年 11 月 13 日
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 件のコメント
JG
2011 年 11 月 16 日
Walter Roberson
2011 年 11 月 16 日
W = {'skate','place','sleep','lefty'};
r = randperm(length(W));
W(r)
0 件のコメント
この質問は閉じられています。
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!