Calculating log for each array element
LUK ShunTim
shuntim.luk at polyu.edu.hk
Fri Jun 20 08:47:18 CDT 2008
DimitryASuplatov wrote:
> Hello,
>
> I have array with some values initialized as
>
> a = load <filename>
>
> I want now to create another array b so as b[i] = log(a[i])
> I do this as follows
>
> for i = 1:length(a)
> b(i) = log(a(i))
> endfor
>
> This works but it takes to long
>
> 1/ Is there any way to speed this up?
Most octave functions works on matrices.
octave:1> a=[1 2 3 4];
octave:2> log(a)
ans =
0.00000 0.69315 1.09861 1.38629
> 2/ How to convert my array a to list?
> 3/ How to append to array?
Is this what you want?
octave:3> b=[a 10]
b =
1 2 3 4 10
octave:4> c=[a b]
c =
1 2 3 4 1 2 3 4 10
>
> I really appreciate your help!
> Thank you!
>
> SDA
The octave manual is online at
http://www.gnu.org/software/octave/doc/interpreter/
Regards,
ST
--
More information about the Help-octave
mailing list