[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Simple Matrix Manipulation Extressions
From: |
John W. Eaton |
Subject: |
Simple Matrix Manipulation Extressions |
Date: |
Mon, 10 Nov 1997 02:36:13 -0600 |
On 8-Nov-1997, john <address@hidden> wrote:
| Are there any simple expressions for these octave expressions:
| In each case I introduce loops, multiplications or something a bit
| horrible to achieve something fairly simple.
|
| 1. given matrix A and row vector V , add V to every row of A
|
| A + ones(rows(A),1) * V
|
| 2. similar problem for multiply:
|
| A * diag(V)
| or A .* ones(rows(A),1) * V
Some future version of Octave will probably allow things like
A .+ V
and
A .* V
to do what you expect. For now, you have to use a multiplication or
indexing tricks to convert the vector to a matrix of the proper size.
| 3. given a matrix A and a scalar s, take the minimum of an element of the
| matrix and the scalar.
|
| (A < s) .* A + (s <= A) .* s)
min (A, s)
| 4. given two same sized matrices A, B, find the pair-wise minimum of each
| element:
| (A < B) .* A + (A >= B) .* B
min (A, B)
I don't know of better ways to do the other tasks you mention.
jwe