stack command errors with multiple column variables of different data types
Afficher commentaires plus anciens
I have a table (imported from a poorly-designed spreadsheet) with repeated column variables I would like to stack. The fields are:
[TestID], [A1], [B1], [C1], [A2], [B2], [C2], ... , [An], [Bn], [Cn]
Any columns under A and B contain numbers. Columns under C contain text.
I would like to stack the table to remove the repeated columns. So the output table fields would be:
[TestID], [Reading], [A], [B], [C]
I am using the following commands (the first line is shortened for brevity):
vars = {{'A1', 'B1', 'C1'}, {'A2', 'B2', 'C2'}, etc, {'An', 'Bn', 'Cn'}};
tblOut = stack(tblIn, vars, 'NewDataVariableNames', {'A', 'B', 'C'}, 'IndexVariableName', 'Reading');
But I get the error:
Error using tabular/stack (line 196)
Error when stacking data variable 'C1'
Caused by:
Conversion to double from cell is not possible.
Why does stack have a problem with the columns having different data types when they are not being stacked into the same column? How do I fix this?
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Data Type Conversion dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!