[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: vectorisation and cell arrays
From: |
Jaroslav Hajek |
Subject: |
Re: vectorisation and cell arrays |
Date: |
Fri, 27 Mar 2009 13:19:07 +0100 |
On Fri, Mar 27, 2009 at 12:32 PM, Bertrand Roessli
<address@hidden> wrote:
> Hello,
>
> Does anybody know if it is possible to vectorize
> matrix operations (the matrices are stored in a cell array)
> on a vector and so to avoid looping over the elements
> of the cell? Thanks in advance
>
> For example
>
> a =
>
> {
> [1,1] =
>
> 1 0 0
> 0 -1 0
> 0 0 1
>
> [1,2] =
>
> 1 0 0
> -1 0 0
> 0 0 -1
>
> e=[1;2;3];
>
> a{1}*e
>
> ans =
>
> 1
> -1
> -3
> works fine, but
> a{:}*e
>
> error: binary operator `*' not implemented for `cs-list' by `matrix'
> operations
>
>
> Bertrand Roessli
>
>
One alternative is to use cellfun(@mtimes, ...), but don't expect top
performance - there's a lot of overhead in calling a function handle.
If you could use a multi-dim array instead, you may be able to do it
using a single multiplication.
cheers
--
RNDr. Jaroslav Hajek
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz