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: Judd Storrs
Subject: Re: Multiply some colums, discarding others
Date: Tue, 24 Nov 2009 14:52:45 -0500

On Tue, Nov 24, 2009 at 2:29 PM, Renato S. Yamane
<address@hidden> wrote:
>
> 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))
>

You can extract columns using this notation

A(:,1)
A(:,2)
A(:,3)

More about this here:
http://www.gnu.org/software/octave/doc/interpreter/Index-Expressions.html#Index-Expressions

You can then compute the second column at once like this:

A(:,2).*cos(A(:,3))

Notice the .* part. This is element wise multiplication instead of
matrix multiplication. More about this here:
http://www.gnu.org/software/octave/doc/interpreter/Arithmetic-Ops.html#Arithmetic-Ops

You can also combine columns using the [ ] syntax. Putting this all
together, I think this does what you want:

[ A(:,1), A(:,2).*cos(A(:,3)) ]


--judd



reply via email to

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