[Top][All Lists]

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

mapper functions vs. cell arrays

From: John W. Eaton
Subject: mapper functions vs. cell arrays
Date: Thu, 31 Aug 2006 12:17:05 -0400

Currently, we have this behavior:

  sin ({1; 2})
  error: mapper: wrong type argument `cell'


  toascii ({"foo"; "foobar"})
  ans =

     102   111   111    32    32    32
     102   111   111    98    97   114

which is equivalent to

  toascii (char ({"foo"; "foobar"}))

I don't think this behavior is intentional.  Octave works this way
because internally, the mapper function converts the cell array of
character strings to a character array.  This behavior seems
surprising to me, since I would have expected either an error (same as
for sin) or toascii to work on each element of the cell array in turn,
which would be equivalent to

  cellfun (@toascii, {"foo"; "foobar"})

I also just found that some of Matlab's character mappers work this
way (generating a cell array of results) but some don't.  For example,

  isspace ({'  ', 'foo bar'}  =>  [0, 0, 0]

Should we be bug-for-bug compatible here, or should we do something
that is more consistent?  I think we should do one of the following:

  * Change all the mapper functions so that

      mapper (CELL) == cellfun (@MAPPER, CELL)


  * Make it so that all mapper functions throw an error if the
    argument is a cell array and expect the user to use cellfun
    explicitly if mapping over the elements cell array is what is




reply via email to

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