Warning: The assignment added rows to the table, but did not assign values to all of the table's existing variables. Those variables will extended with rows containing default values.
80 次查看(过去 30 天)
显示 更早的评论
Why do I recieve this warning?
0 个评论
采纳的回答
dpb
2019-10-20
Apparently you had a table with N variables but only assigned values to a subset of those when adding rows.
Example:
>> x=rand(3,1);y=rand(3,1); % some dummy data
>> t=table(x,y) % turn into table
t =
3×2 table
x y
________ _______
0.021833 0.20422
0.3931 0.66228
0.25254 0.91474
>> t.y(4)=0.5; % add a y row, but forget about x
Warning: The assignment added rows to the table, but did not assign values to all of the
table's existing variables. Those variables have been extended with rows containing default
values.
> In tabular/subsasgnDot (line 457)
In tabular/subsasgn (line 67)
>> t % so what did it do???
t =
4×2 table
x y
________ _______
0.021833 0.20422
0.3931 0.66228
0.25254 0.91474
0 0.5
>>
As shown, it added the y value as asked, but filled in a zero (default value) for x.
Always add for every variable (even if want the default value) to avoid the warning. You could disable the warning if doing this deliberately, but I really wouldn't recommend that over explicit assignment.
2 个评论
Sven Larsen
2022-11-7
your answer does not provide solution to problem at all. This error is received even, if we do:
t.x(4)=0.5;
t.y(4)=0.5;
Basic Matlab vagueness and annoyance...
dpb
2022-11-7
编辑:dpb
2022-11-8
Your code above still only added "x" the first time so the warning (and it is a warning, not a fatal error) is still correct; at that point there was still missing the corresponding "y"
As the Answer says, you must add all element of the table in the same operation to avoid the warning -- or, of course, you can always turn off the warning selectively if you're knowing you're going to be doing this in a section of code.
x=rand(3,1);y=rand(3,1); % some dummy data
t=table(x,y); % turn into table
xynew=[0.5 pi];
t=[t;array2table(xynew,'variablenames',t.Properties.VariableNames)]
and, Voila! no warning.
I made an enhancement request/suggestion to create a new functionality for the table/timetable class of addrecord that would add the default record of proper type to the existing table either as empty, partially, or fully populated. Then, there would be specific syntax for the above.
t(end+1,:)=array2table(xynew,'variablenames',t.Properties.VariableNames)
would be an alternative syntax to do the same thing.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!