# extracting submatrices from cell

7 views (last 30 days)
Daniel on 27 Apr 2013
Consider the following bit of code:
X={1, 'a'; 'b', 3.14};
X(2,:)
X{2,:}
It produces the following output:
ans = 'b' [3.1400]
ans = b
ans = 3.1400
Can anyone explain to me the reason for the difference. I would have expected the statement X(2,:) to fail and that X{2,:} would have produced what X(2,:) did, in fact, produce.

Ahmed A. Selman on 27 Apr 2013
Try the same example with:
X={1, 'a'; 'b', 3.14};
K1=X(2,:)
[K21 K22]=X{2,:}
Then use
whos
to see that K1 is a cell, i.e., it only puts part from X into K1, while [K21 K22] is [char double], extracting the contents of the cell into a matrix. The first operation (K1) is another way for cell concatenation.
##### 2 CommentsShowHide 1 older comment
Ahmed A. Selman on 27 Apr 2013
(,) is a portioning, or concatenation process; while
{,} is an extraction, or transformation one .. :)

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!