フィルターのクリア

How can you create an empty table object with non-zero rows or non-zero columns?

31 ビュー (過去 30 日間)
Anil
Anil 2014 年 1 月 15 日
回答済み: Peter Perkins 2017 年 2 月 28 日
I am trying to initialise a table object of the correct dimension but not initialised with any data. This is possible with other native arrays, but I can't work out how to do it with a table.
Specifically, I'd like to be able to build a [0 x N] or [N x 0] table, so I can either add rows or columns one by one.

回答 (2 件)

Jacob Halbrooks
Jacob Halbrooks 2014 年 1 月 15 日
編集済み: Jacob Halbrooks 2014 年 1 月 15 日
You can use cell2table to initialize an empty table by providing a cell array of desired dimensions. For example, this initializes an empty table with 0 rows and 5 variables:
T = cell2table(cell(0,5));
Now you can add data by concatenation with another table. For example, this adds a row of data to the table created above:
T = [T ; cell2table({1,2,3,4,5})];
  3 件のコメント
Richard Allen
Richard Allen 2017 年 2 月 23 日
You should probably just use
T = table
Peter Perkins
Peter Perkins 2017 年 2 月 28 日
T = table is going to create a 0x0. That may be a good starting point, but strictly speaking it's not what the OP asked for.

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


Peter Perkins
Peter Perkins 2017 年 2 月 28 日
Really, the question is kind of ill-posed, because to create an empty table with a non-zero number of variables, you need to define what type each variable in a table is even if the table has zero rows.
>> array2table(zeros(0,5))
ans =
0×5 empty table
creates an empty table with five variables, but all five are doubles, which may or may not be what you want. Ditto for cell2table(cell(0,5)). In general, you need to do something like
t = table(zeros(0,1),zeros(0,1,'single'),cell(0,1))
to define the data types.

カテゴリ

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

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by