add new row to table with missing values
47 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
How can I add a new row to an existing table with missing values?
For illustration, I define a table T with 4 variables: name, city, age, height.
V.name = "Ann";
V.city = "Berlin";
V.age = 24;
V.height = 172;
T = struct2table(V);
Now, I want to add another row to this table where the new row only contains values for 3 of the variables (out of 4).
V2.name = "Luka";
V2.city = "Tokyo";
V2.age = 30;
T = [T; struct2table(V2)];
This leads to the following error:
"All tables being vertically concatenated must have the same number of variables."
What's the best practice for such situations?
0 Kommentare
Antworten (1)
KSSV
am 18 Jan. 2022
V.name = "Ann";
V.city = "Berlin";
V.age = 24;
V.height = 172;
T1 = struct2table(V);
V2.name = "Luka";
V2.city = "Tokyo";
V2.age = 30;
T2 = struct2table(V2);
T2.height = NaN ;
T = [T1;T2]
4 Kommentare
Siehe auch
Kategorien
Mehr zu Structures finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!