[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Calculating log for each array element
From: |
Jaroslav Hajek |
Subject: |
Re: Calculating log for each array element |
Date: |
Fri, 20 Jun 2008 15:18:48 +0200 |
On Fri, Jun 20, 2008 at 2:40 PM, DimitryASuplatov <address@hidden> 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?
Try
b = log(a);
(semicolon means the result is not dumped to screen)
> 2/ How to convert my array a to list?
In general, there is no need. Arrays are dynamic, so they can grow as needed,
although it is usually beneficial to pre-allocate if you can. You can
use cell arrays
if you want to.
> 3/ How to append to array?
Use array constructor, "*cat", or simply assign out of bounds. All the
following expressions append "x" to a row vector "array":
array = [array,x];
array = horzcat(array, );
array(end+1) = x;
Note that Octave distinguishes column vectors and row vectors, as in
linear algebra.
Sometimes the distinction matters, sometimes not.
>
> I really appreciate your help!
> Thank you!
>
> SDA
>
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://www.cae.wisc.edu/mailman/listinfo/help-octave
>
--
RNDr. Jaroslav Hajek
computing expert
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz