Randomly Choose number from a matrix of several numbers?
조회 수: 3 (최근 30일)
이전 댓글 표시
Hello all, I will attempt to describe what I need help with the best I can.
while response == 1 || response == 2
if response == 1
N1=rand%number according to IGT (50% chance of being 0)
N2=rand%number according to IGT
totala= total - N1;
fprintf(('You Lost:%.0f'),N1)
totalb= total + N2;
fprintf(('You Won:%.0f'),N2)
elseif response == 1 && N == [10,20,30,40,50,60,70,80,90]
N1=rand%number according to IGT + 10% increased chance of penalty (<50% chance of being 0)
N2=rand%number according to IGT
totala= total - N1;
fprintf(('You Lost:%.0f'),N1)
totalb= total + N2;
fprintf(('You Won:%.0f'),N2)
end
Where N1 and N2 will be a matrix (1xn) for example x=[50,50,0,0,250,350,450,500,500] I need the code to randomly select a number out of this matrix first, and if that works out, I would like to randomly select it to either be 0, or a number from that list. (if necessary, I can simply place 0's in the list)
This is essentially based off of the Iowa Gambling Task(IGT). As a person chooses a disadvantageous deck, they are penalized more over the long term than if one were to pick from the more advantageous decks. I don't feel comfortable sharing all of the program, but if needed, I'd be happy to send it via email for help.
Ignore the whole +10% increases, I plan on discussing this with my professor tomorrow and seeing if it is needed
Please feel free to ask for any other info Thanks,
Joe
댓글 수: 0
답변 (1개)
Sarah Wait Zaranek
2012년 2월 21일
Instead of starting with your code - I will give an example of how I would do it. Hopefully this can see how you implement it in your large framework.
x = rand(10,1); % some matrix you want to sample from
idx = randi(length(x)) % random index into x
randomval = x(idx);
if randi(2)-1 % half the time assign to zero
randomval = 0;
end
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!