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.

조회 수: 86 (최근 30일)
Why do I recieve this warning?

채택된 답변

dpb
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
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
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)]
t = 4×2 table
x y _______ ________ 0.50943 0.47535 0.50019 0.73985 0.80566 0.044596 0.5 3.1416
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)
t = 5×2 table
x y _______ ________ 0.50943 0.47535 0.50019 0.73985 0.80566 0.044596 0.5 3.1416 0.5 3.1416
would be an alternative syntax to do the same thing.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by