How to define an empty table with variable type of a column as a matrix?

29 ビュー (過去 30 日間)
Parth-Raj Singh
Parth-Raj Singh 2020 年 7 月 17 日
コメント済み: Star Strider 2020 年 7 月 20 日
Hello everyone,
I want to create an empty table with variable type of a column as a matrix.
I tried
tab = table('Size',[10,2],'VariableTypes',["double","double"]);
tab{1,1} = zeros(1,50); % I want to do this
tab{1,2} = zeros(1,25); % I want to do this
% Error : The value on the right-hand side of the assignment has the wrong width. The assignment requires a value whose width is 1.
I understant this error however, I would like to know how can it be solved.
Thanks
  2 件のコメント
Fangjun Jiang
Fangjun Jiang 2020 年 7 月 17 日
You specified the table size as [10,2]. tab{1,1} and tab{1,2} is already a scalar whose value is 0.
You can't assign it to be a vector of 50 zeros or 25 zeros.
Parth-Raj Singh
Parth-Raj Singh 2020 年 7 月 20 日
As I already mentioned, I understand the problem.
Thanks anyway.

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

採用された回答

Star Strider
Star Strider 2020 年 7 月 17 日
I doubt that has a solution, with the way you created ‘tab’ originally, since it exceeds the column size you set for it.
You can do something like this, however that is a good as it gets:
tab = table('Size',[50,2],'VariableTypes',["double","double"]);
tab{1:50,1} = rand(50,1);
tab{1:25,2} = rand(25,1);
.
  6 件のコメント
Parth-Raj Singh
Parth-Raj Singh 2020 年 7 月 20 日
Yes, this seems to be the only option I have left based on my requirements. Thanks a lot.
Star Strider
Star Strider 2020 年 7 月 20 日
As always, my pleasure!

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

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by