Cell arrays in MATLAB

1 回表示 (過去 30 日間)
med-sweng
med-sweng 2013 年 8 月 7 日
I know what a cell array is. I just came to the following line: cell_array = cell([], 1);
What does that mean? How can we read the above line?
Thanks.

回答 (3 件)

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 8 月 7 日
That means you an empty cell
  1 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 8 月 7 日
編集済み: Azzi Abdelmalek 2013 年 8 月 7 日
The only difference between a={} and b=cell([],10) is their sizes, both do not pre-allocate memory
% size(a)= [0 0]
% size(b)= [0 10]

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


Caroline
Caroline 2013 年 8 月 7 日
The cell function creates a cell array. There are multiple ways to use it. In this case it would create an empty cell array. If you typed the following line into the MATLAB command window:
cell_array = cell([], 1);
it would return the following:
cell_array =
Empty cell array: 0-by-1

per isakson
per isakson 2013 年 8 月 7 日
編集済み: per isakson 2013 年 8 月 7 日
Create an empty column cell array
>> cell_array = cell([], 1);
>> whos
Name Size Bytes Class Attributes
cell_array 0x1 0 cell
which might be useful in a loop, in which you may concatenate a column cell array but not a row cell array
>> cell_array = cat( 1, cell_array, {'a';'b'} )
cell_array =
'a'
'b'
>> cell_array = cell([], 1);
>> cell_array = cat( 1, cell_array, {'a','b'} )
Error using cat
Dimensions of matrices being concatenated are not consistent.
Equivalent to cell_array = cell(0,1);

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by