• Hi! I need to write a code on casting dice and our instructor wants it to be like;
  • 1- Our range is from 0 to 1
  • 2- Divide the range to 6 (so we will have 6 sections to present a number on dice)
  • 3- Pick a random number between 0 and 1
  • 4- Determine that in which section is this number (if it is in second section that means dice showing 2)
  • 5- Increase the counter by one
  • 6- Run it N=100 cycles
  • So I will have the number of accurances for each section than I'm going to make a plot.
  • I'm stuck at second step. I can't define the sections such as;
  • section1=(0:0.1667)
  • section2=(0.1668:0.3333)
  • .
  • .
  • .
  • Can you help me out?
  • Thanks

답변 (1개)

Star Strider
Star Strider 2014년 10월 9일

0 개 추천

The linspace function is your friend here:
sections = linspace(0,1,6);

댓글 수: 3

Emre
Emre 2014년 10월 9일
Thanks but I want all this sections to be seperated
José-Luis
José-Luis 2014년 10월 9일
So you want somebody to do your homework for you...
Still not certain I understand exactly what you want, but this may get you started:
sectlims = linspace(0,1,7);
for k1 = 1:length(sectlims)-1
section(k1,:) = [sectlims(k1) sectlims(k1+1)];
end
You will need to test for ‘ > ’ the lower limits and ‘ <= ’ the upper limit to avoid overlap.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

질문:

2014년 10월 9일

댓글:

2014년 10월 9일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by