binary operations on cell arrays?
Dushan Mitrovich
dushanm at spinn.net
Fri Dec 28 18:05:40 CST 2007
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
More information about the Help-octave
mailing list