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!