Trying to repeat this for loop

wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwweeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee

1 commentaire

Azzi Abdelmalek
Azzi Abdelmalek le 7 Mai 2013
Why did you delete the question?

Réponses (1)

Azzi Abdelmalek
Azzi Abdelmalek le 3 Mai 2013
Modifié(e) : Azzi Abdelmalek le 3 Mai 2013

2 votes

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 commentaires

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

Cette question est clôturée.

Question posée :

le 3 Mai 2013

Clôturé :

le 20 Août 2021

Community Treasure Hunt

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

Start Hunting!

Translated by