• Support PF! Buy your school textbooks, materials and every day products Here!

MATLAB - repeating a command

  • #1

Homework Statement



Hi. The problem assigned to me is to take a column vector of 100 entries and then to randomly assign add a 0 or 1 to a random entry, and then to repeat this "n" # of times, where the upper "n" is 1 million.

I have this so far

h = zeros(100,1)
h(round(rand(1)*100)) = randint(1) + h(round(rand(1)*100))

If I manually copy and paste the bottom command in MATLAB, it seems to work fine, but obviously I can't copy and paste this a million times. I don't know how to implement a "for" loop exactly, for this cause. Any help would be greatly appreciated, thanks.
 

Answers and Replies

  • #2
33,164
4,848
Look at the other thread you posted. In that thread you were given an example of how to implement a for loop in matlab.
 
  • #3
Figured it out; the problem wasn't the for loop. Thx.
 
Last edited:

Related Threads for: MATLAB - repeating a command

  • Last Post
Replies
4
Views
3K
  • Last Post
Replies
0
Views
3K
Replies
1
Views
16K
Replies
5
Views
4K
Replies
3
Views
4K
  • Last Post
Replies
1
Views
5K
  • Last Post
Replies
6
Views
572
Top