How can I assign a single column of a 0x10 empty table
10 ビュー (過去 30 日間)
古いコメントを表示
Hello folks,
I have a 0x10 empty table. That is: the table variables are declared but there is no actual data entries in the table. Let's call it
myTable
I am trying to assign the first column of the table like so:
myTable.firstVariable = [0:1:length(x)]';
But alas this returns the following error:
To assign to or create a variable in a table, the number of rows must match the height of the table.
Of course, the height of the table is currently 0. Its height will be dictated by another variable x. I do not care what the other variables will be populated with at this time (i.e. [], or 0, or NaN, or whatever), I will populate them later.
How can I assign the first variable?
Thank you!
PS: I cannot use a struct or array. The datatype must remain as a table.
0 件のコメント
採用された回答
Star Strider
2021 年 11 月 29 日
Preallocation for table arrays is possible.
myTable = table('Size',[10 1], 'VariableNames',{'firstVariable'}, 'VariableTypes',{'double'})
myTable.firstVariable = (1:numel(myTable.firstVariable)).'
.
0 件のコメント
その他の回答 (1 件)
Matt J
2021 年 11 月 29 日
編集済み: Matt J
2021 年 11 月 29 日
I cannot use a struct or array. The datatype must remain as a table.
You cannot avoid wokring with arrays as an intermediary, however, the data does not have to remain as an array. You can convert it to a table, e.g.,
T=nan(5,10);
T(:,1)=1:5;
T=array2table(T)
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Tables についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!