Cell Array referencing question

2 ビュー (過去 30 日間)
Rick
Rick 2014 年 7 月 4 日
コメント済み: the cyclist 2014 年 7 月 5 日
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 1x1 cell, and B is a 1x2 cell. I am confused about what matlab is doing when it sees this and why it is being classified as such.
  1 件のコメント
the cyclist
the cyclist 2014 年 7 月 5 日
You might learn from this introduction to cell arrays.

サインインしてコメントする。

採用された回答

the cyclist
the cyclist 2014 年 7 月 4 日
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?
  2 件のコメント
Rick
Rick 2014 年 7 月 4 日
How is matlab reading this?
B = {3,4}; C = [{3},{4}];
They are equivalent. B has two cells in one cell array. C is two cell arrays each containing one cell. Why are they the same?
the cyclist
the cyclist 2014 年 7 月 5 日
編集済み: the cyclist 2014 年 7 月 5 日
In your first example, B is the direct specification of a 1x2 cell array.
In your second example, {3} is a 1x1 cell array, {4} is a 1x1 cell array, and then C is the concatenation of those "horizontally", creating a 1x2 cell array.
Hence, the equivalence.

サインインしてコメントする。

その他の回答 (1 件)

Ben11
Ben11 2014 年 7 月 4 日
編集済み: Ben11 2014 年 7 月 4 日
Actually B contains a 1x2 double and it contains only 1 element (a 1x2 vector) whereas A contains 2 elements, i.e. 2 1x1 vectors if you wish

カテゴリ

Help Center および File ExchangeCell Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by