Create a new table based on cell array

1 回表示 (過去 30 日間)
as hz
as hz 2013 年 10 月 15 日
コメント済み: Cedric 2013 年 10 月 15 日
Hi,
Is there a better way to create the table below (Its a new table consist of id number and cell array data)?
Thanks.
cData=[;];
for i = 1 : length(cellarray)
objectNumber=i;
currentObject=cellarray{i};
newDataRow = {objectNumber, currentObject};
cData=[cData;newDataRow];
disp(cData);
end

採用された回答

Cedric
Cedric 2013 年 10 月 15 日
Yes
dataId = num2cell( 1:numel( cellarray )).' ;
cData = [dataId, cellarray] ;
  2 件のコメント
as hz
as hz 2013 年 10 月 15 日
Thanks. Wow, great...
And if I wish to add also a text field in your code?.
This would be my code.
newDataRow = {objectNumber, currentObject,'text'};
Cedric
Cedric 2013 年 10 月 15 日
I am using square brackets actually, which concatenate cell arrays dataId and cellarray. If you had another cell array with whatever content that you wanted to concatenate, you could do the same, e.g.
cData = [dataId, cellarray, labels] ;
but labels would have to have the same number of rows as cellarray (which is mandatory for horizontal concatenation). If you wanted to have only the first cell defined with some text content, you would still have to do something like
labels = cell( size( cellarray )) ;
labels{1} = 'Some text' ;
cData = [dataId, cellarray, labels] ;

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by