help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Multiply some colums, discarding others


From: Jaroslav Hajek
Subject: Re: Multiply some colums, discarding others
Date: Tue, 24 Nov 2009 21:27:00 +0100



On Tue, Nov 24, 2009 at 9:15 PM, Ron.Simonson <address@hidden> wrote:
Good afternoon Renato,  The approach I would take to your
problem is as follows:

# Matrix A is "freq", "impedance" and "phase", like this:

# properly define the Matrix A
A = [20.66, 12.32, 49.63;
     21.47, 13.75, 48.86;
     22.30, 15.92, 47.71;
     23.17, 18.43, 45.06;
     24.07, 22.61, 39.76];

# I would like to get another Matrix, B, with the result of
# multiplication of "impedance" and "phase":
#
#       A(1,2) * cos(A(1,3)
#       A(2,2) * cos(A(2,3))
#       A(3,2) * cos(A(3,3))
#       A(4,2) * cos(A(4,3))
#       A(5,2) * cos(A(5,3))
#
#
# Matrix "B" =
#
#       20.66      A(1,2) * cos(A(1,3))
#       21.47      A(2,2) * cos(A(2,3))
#       22.30      A(3,2) * cos(A(3,3))
#       23.17      A(4,2) * cos(A(4,3))
#       24.07      A(5,2) * cos(A(5,3))

freq = A(:,1);      # extract column 1 data into freq vector
impedance = A(:,2); # extract column 2 data into impedance vector
phase = A(:,3);     # extract column 3 data into phase vector

B = [freq impedance .* cos(phase)]; # generate desired B matrix
B
clear freq impedance phase; # scuttle freq, impedance, and phase vectors
# clearing variables helps to recover memory when needed

Though not efficient in terms of storage and likely speed, extracting
the data into named variables helps me to keep track of what each
variable is.  I am not an expert by any means.


Basically all Octave expressions are reference-counted values, so storing an _expression_ into a variable never (well, almost never) causes any extra copying. Hence your approach carries essentially no extra penalty.
 
--
RNDr. Jaroslav Hajek
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz

reply via email to

[Prev in Thread] Current Thread [Next in Thread]