Trying to repeat this for loop

wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwweeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee

回答(1 个)

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 个评论

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.
you can use diff function
d=diff(p(1:100))
result=d==0
out=sum(result)
Are you saying to do that instead of the for loop?
Yes
p=[1 4 10 18]
diff(p)=[4-1 10-4 18-10]
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