MATLAB: Cell Array referencing question

cell arrays

Hello,
Suppose I have
A = {1 2}
A =
[1] [2]
and
B = {[1 2]}
B =
[1x2 double]
I am wondering, why are these different. Matlab Says A is a 1×1 cell, and B is a 1×2 cell. I am confused about what matlab is doing when it sees this and why it is being classified as such.

Best Answer

  • Your first statement is syntactically equivalent to
    A = {[1],[2]};
    This is specifying that A is a 1x2 cell array, where the first element is the length-1 vector [1], and the second element is [2].
    In your second statement,
    B = {[1 2]}
    you have specified that B is a 1x1 cell array, where the contents of that one cell is the 1x2 vector [1 2].
    Does that help?