Trying to repeat this for loop

wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwweeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee

1 comentario

Azzi Abdelmalek
Azzi Abdelmalek el 7 de Mayo de 2013
Why did you delete the question?

Respuestas (1)

Azzi Abdelmalek
Azzi Abdelmalek el 3 de Mayo de 2013
Editada: Azzi Abdelmalek el 3 de Mayo de 2013

2 votos

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 comentarios

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

La pregunta está cerrada.

Preguntada:

el 3 de Mayo de 2013

Cerrada:

el 20 de Ag. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by