"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