looping a sequence easiest

조회 수: 1 (최근 30일)
Rasmus
Rasmus 2014년 4월 16일
댓글: Mischa Kim 2014년 4월 16일
hello guys!
which way would be the easiest to make a loop of a sequence 1000 times ?
this is my code
-------------------------------------------------------
x0=[zeros(1,276) ones(1,290)]; x=x0(randperm(566)); b=(0:566); d=[x 0]-[0 x]; l=(b(d==(-1))-b(d==1)) L=max(l) -------------------------------
I need L in a propability assignment. For that I need 1000 different results and put it into a histogram. So I need the sequence to repeat it self 1000 times.
How do you do that?

채택된 답변

Mischa Kim
Mischa Kim 2014년 4월 16일
편집: Mischa Kim 2014년 4월 16일
Something like
x0 = [zeros(1,276) ones(1,290)];
L = zeros(1,1000);
b = (0:566);
for ii = 1:1000
x = x0(randperm(566));
d = [x 0] - [0 x];
l = (b(d==(-1)) - b(d==1));
L(ii) = max(l);
end
  댓글 수: 2
Rasmus
Rasmus 2014년 4월 16일
How would you get all the data over in a histgram. For some reason when i say
result=hist(L(ii),1:10)
it only gives me one value in it.
Mischa Kim
Mischa Kim 2014년 4월 16일
Use
result = hist(L)
or
hist(L) % to plot

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Histograms에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by