help-octave
[Top][All Lists]
Advanced

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

binary operations on cell arrays?


From: Dushan Mitrovich
Subject: binary operations on cell arrays?
Date: Fri, 28 Dec 2007 17:05:40 -0700
User-agent: VSoup v1.2.9.48Beta [OS/2]

As I understand it, 'cellfun' is supposed to be able to apply a function
to each cell of a cell array, and to operate on two or more cell arrays
if the function takes that many arrays as arguments.  But what about
simple binary operations between cell values?  If cell arrays A and B
have identical sizes and the cells have identical numeric content types
(scalar, vector, matrix, complex, ...), is there an existing way to ob-
tain, for example, C{j,k} = A{j,k} - B{j,k} for every j and k within the
cell array dimensions?

This is straightforward using 'for' loops, but is there a vectorized way
to do it?  One thought was to define functions taking two arguments that
apply the desired binary operators, and using those functions (or func-
tion handles) in 'cellfun'.  So if 'a' and 'b' are numeric, the function
'plus.m' would produce

    plus(a,b) = a + b

Then 'cellfun' would simply distribute this function over all the cells
of the involved cell arrays.  Does something already exist to do this?
If not, is this the best way to go about it?

- Dushan Mitrovich



reply via email to

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