Is There an Inconsistency with How Unassigned Values are Filled After an Assignment into a Table?
Show older comments
Create an empty table
T = table;
Assign a string value to the third row a new variable
T.string(3) = "abc"
The values in rows 1 and 2 are assigned as <missing>. Same basic behavior with a datetime
T.date(3) = datetime
Do the same thing with a numeric
T.number(3) = 5
I was expecting the unassigned number values to be filled with the @doc:missing value that corresponds to a double, which is NaN. Alas, it fills in with zeros, so now we can't go back afterwards and find which were the missing values that were automagically filled
ismissing(T)
I realize that filling with NaN would be problematic if NaN is a valid entry that could be assigned to an element of T.number, but it seems like filling with NaN would be better than zero in the majority of cases and that it would be more consistent with the other data types.
Or perhaps it's intended that T.num(3) = 5 should fill with zeros to consistent with how Matlab initizalizes unassigned elements of vectors?
x(3) = 5
I think that's a typical use case, but I'm not sure that same paradigm follows for data arranged in a table.
Accepted Answer
More Answers (1)
T(3) = "abc"
U(3) = datetime('now')
x(3) = 5
So the filling is consistent with arrays.
Categories
Find more on Tables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!