Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

WHAT IS THE INVERSE OF CELL2MAT?

356 views
Skip to first unread message

Greg Heath

unread,
Sep 30, 2015, 9:03:09 PM9/30/15
to
HOW IS THE FOLLOWING EXPLAINED?

Y1 = { 1 2 3 }
y1 = cell2mat(Y1)
Y2 = {y1}
y2 = cell2mat(Y2)
isequal(y1,y2) % 1
isequal( Y1, Y2 ) % 0

Thanks,

Greg

dpb

unread,
Oct 1, 2015, 1:02:54 AM10/1/15
to
This help?

>> whos y* Y*
Name Size Bytes Class Attributes

Y1 1x3 204 cell
Y2 1x1 84 cell
y1 1x3 24 double
y2 1x3 24 double

>>

--

Steven Lord

unread,
Oct 1, 2015, 11:09:36 AM10/1/15
to


"Greg Heath" <he...@alumni.brown.edu> wrote in message
news:mui0o8$hl5$1...@newscl01ah.mathworks.com...
> HOW IS THE FOLLOWING EXPLAINED?
>
> Y1 = { 1 2 3 }

This forms a 1-by-3 cell array where each cell contains a scalar.

> y1 = cell2mat(Y1)

This concatenates together cells 1, 2, and 3 of Y1. This forms a 1-by-3
double array.

> Y2 = {y1}

This forms a 1-by-1 cell array where the one cell contains a 1-by-3 double
array.

> y2 = cell2mat(Y2)

This concatenates together cell 1 of Y2. This forms a 1-by-3 double array.

> isequal(y1,y2) % 1

Correct.

> isequal( Y1, Y2 ) % 0

Also correct.

Let's say that I have three egg cartons. Each carton contains one egg.
[Assume I held an Easter party and each of the three families I invited ate
all but one of the eggs they each brought.] I can combine them into one
carton containing three eggs. Or I can start out with one egg carton
containing three eggs and pack all the eggs into one carton trivially. In
either case, I end up with one egg carton containing 3 eggs.

To answer the question asked in the subject, depending on how you want the
arrays partitioned either MAT2CELL or NUM2CELL is the inverse of CELL2MAT.
In this case I'd use NUM2CELL to regenerate Y1 from y1, since you're not
doing anything "fancy" with respect to how you want to subdivide the matrix.
If I had:

M = magic(5);

and I wanted to break it into a 3-by-3 cell array whose middle row and
column contained just a single row or column of M respectively, then I'd use
MAT2CELL.

MC = mat2cell(M, [2 1 2], [2 1 2])
isequal(M, cell2mat(MC))

--
Steve Lord
sl...@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Greg Heath

unread,
Oct 5, 2015, 5:40:14 AM10/5/15
to
"Steven Lord" <Steve...@mathworks.com> wrote in message <mujiba$465$1...@newscl01ah.mathworks.com>...
Thanks. I had forgotten about num2cell.

Greg

Greg Heath

unread,
Oct 5, 2015, 5:58:09 AM10/5/15
to
...
> > To answer the question asked in the subject, depending on how you want the
> > arrays partitioned either MAT2CELL or NUM2CELL is the inverse of CELL2MAT.
>
>
> Thanks. I had forgotten about num2cell.

WHOOPS! I also forgot about

CON2SEQ

Greg

Bruno Luong

unread,
Oct 5, 2015, 6:50:15 AM10/5/15
to
"Greg Heath" <he...@alumni.brown.edu> wrote in message <muthjb$hs1$1...@newscl01ah.mathworks.com>...

>
> WHOOPS! I also forgot about
>
> CON2SEQ
>

Is it TMW's function?

Steven Lord

unread,
Oct 5, 2015, 9:39:08 AM10/5/15
to


"Bruno Luong" <b.l...@fogale.findmycountry> wrote in message
news:mutkl0$nr9$1...@newscl01ah.mathworks.com...
It is in Neural Network Toolbox.

http://www.mathworks.com/help/nnet/ref/con2seq.html
0 new messages