Trying to repeat this for loop

wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwweeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee

Risposte (1)

Azzi Abdelmalek
Azzi Abdelmalek il 3 Mag 2013
Modificato: Azzi Abdelmalek il 3 Mag 2013
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 Commenti

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

Questa domanda è chiusa.

Richiesto:

il 3 Mag 2013

Chiuso:

il 20 Ago 2021

Community Treasure Hunt

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

Start Hunting!

Translated by