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
此问题已关闭。
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!