Author Topic: For loop  (Read 485 times)

Offline nuvoletta74

  • Newbie
  • *
  • Posts: 1
    • View Profile
For loop
« on: July 05, 2009, 09:03:33 PM »
hi I'm very new to Matlab and I have a problem with a for loop which I am sure is straightforward but I cant work it out at all.
 
 I have this problem:
 
 I want to generate a vector which is 1673 rows of a constant number.  I then want to use a loop to multiply this vector by a number between 1 and 40 and save each of the 40 vectors in a maxtrix.
 
 To try and work this out I have generated a vector of "ones" and then I tried to multiply this in the loop by each number between 1 and 40 to get a series of vectors which only contain 1's, 2's, 3's etc all the way up to 40's.
 
 This is the script I am using but it clearly doesnt work....
 
 n=40
 z=ones(1676,1);
 for i = 2:n
 z(i)=z*i
 end
 
 as you can see there isnt much I could get wrong but I have somwhere.....help!!!

Matlab and SimuLink Development Forum

For loop
« on: July 05, 2009, 09:03:33 PM »