Trying to repeat this for loop

wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwweeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee

1 件のコメント

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 5 月 7 日
Why did you delete the question?

回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 5 月 3 日
編集済み: Azzi Abdelmalek 2013 年 5 月 3 日

2 投票

put the loop inside another loop. Can give more details how do you want to repeat this loop?
Edit
d=diff(p(1:100))
result=d==0
out=sum(result)

5 件のコメント

tunny
tunny 2013 年 5 月 3 日
The for loop I have right now is determining whether there are two of the same numbers next to each other in my array "p". I just need to repeat this 1000 times to determine the average number of times there was numbers of the same value next to each other in the array.
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 5 月 3 日
編集済み: Azzi Abdelmalek 2013 年 5 月 3 日
you can use diff function
d=diff(p(1:100))
result=d==0
out=sum(result)
tunny
tunny 2013 年 5 月 3 日
Are you saying to do that instead of the for loop?
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 5 月 3 日
編集済み: Azzi Abdelmalek 2013 年 5 月 3 日
Yes
p=[1 4 10 18]
diff(p)=[4-1 10-4 18-10]
tunny
tunny 2013 年 5 月 3 日
Okay I finally figured it out. I needed my random number generator in the loop to for the 1000 iterations. Your idea works great, thank you so much.

この質問は閉じられています。

質問済み:

2013 年 5 月 3 日

閉鎖済み:

2021 年 8 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by