different behaviour when concatenating table colums
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
The two lines behave differently:
tmp = [all_table.('SpO2_FiO2');myTable.('SpO2_FiO2')]; % this works
tmp = [all_table(:,52);myTable(:,52)]; % this gives error 'Cannot concatenate the table variable 'SpO2_FiO2' because it is a cell in one table and a non-cell in another.'
52 is the column index to the column named ''SpO2_FiO2". The type of this column is double in both tables, all_table and my_Table.
0 commentaires
Réponses (1)
Voss
le 23 Déc 2021
If both tables' SpO2_FiO2 columns are actually doubles, then both ways of concatenating do the same thing:
SpO2_FiO2 = (1:3).';
all_table = table(SpO2_FiO2)
myTable = table(SpO2_FiO2)
tmp = [all_table.('SpO2_FiO2');myTable.('SpO2_FiO2')]
tmp = [all_table(:,1);myTable(:,1)]
If instead one table's SpO2_FiO2 column is a cell array, then you get behavior consistent with what you observe:
SpO2_FiO2 = (1:3).';
all_table = table(SpO2_FiO2)
SpO2_FiO2 = num2cell(SpO2_FiO2);
myTable = table(SpO2_FiO2)
tmp = [all_table.('SpO2_FiO2');myTable.('SpO2_FiO2')]
tmp = [all_table(:,1);myTable(:,1)]
In the second case, the line:
tmp = [all_table.('SpO2_FiO2');myTable.('SpO2_FiO2')];
does not generate an error, but it doesn't necessarily 'work' because it doesn't necessarily do what you want. It gives a 4-by-1 cell array where the first element is a 3-by-1 vector of doubles and the 2nd, 3rd, and 4th elements are all scalar doubles, as opposed to a 6-by-1 vector of doubles, which is what you get either way you do the concatenation when both columns are actually doubles.
0 commentaires
Voir également
Catégories
En savoir plus sur Tables dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!