[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: optimize code
From: |
Macy |
Subject: |
Re: optimize code |
Date: |
Mon, 2 Dec 2013 05:47:17 -0800 |
Jonas,
You would have discovered this on your own but probably a good idea to use the
line terminator ; else you'll print a list of values.
*if* you did the for loop as shown, you would have gotten a different, and
random value, for each term. Octave very kindly re-seeds the random function,
[it is my understanding] Fortran and Basic do not.
What you wrote would have produced identical to
vector=rand(1,10);
However keep in mind that you can also make the vector other ways:
vector=rand(10,1);
just in case you need it a different type.
--- address@hidden wrote:
From: Jonas Åberg <address@hidden>
To: "address@hidden" <address@hidden>
Subject: optimize code
Date: Mon, 2 Dec 2013 11:28:39 +0000
It is a bit of a newbie problem this, but can this be vectorised?
In principle I need to do
for i=1:10
vector(i)=rand
endfor
I would like to do it by using something that "looks" somewhat like this
vector(1:10)=rand
Where different random values are assigned to the different positions of the
vector.
Of course, the way I wrote it the same random value is assigned to all
positions of vector, but I don't want that...
Is this possible?
/Jonas
- optimize code, Jonas Åberg, 2013/12/02
- Re: optimize code,
Macy <=