Adding a categorical column to a Table
Mostrar comentarios más antiguos
Dear All,
I've been stucked with a fairly simple problem for a couple of hours now. I'd like to know how to add a new categorical column to a table in which:
1) from cell 1 to 68 I want to add a string value called 'v';
2) from 69 to 100 I want to add a string value called 'a';
3) from 101 to 155 I want to add a string value called 'i'
Is there an easy way to write that? cause I could do it manually, but I'd like to know the right way to do it when working with tables (or arrays also).
This is what I was trying to do:
>> tabPC = table(PC1, PC2, PC3); %this is a 155x3 table
>> tabPC.Var4{1,1} = 'v';
>> tabPC.Var4{69} = 'a';
>> tabPC.Var4{101} = 'i';
>> tabPC.Properties.VariableNames{4} = 'mycategories';
>> tabPC.mycategories = categorical(tabPC.mycategories)
This code just added a new 4th column to the original table (named 'mycategories' ) with 'v', 'a' and 'i' strings into the 1th, 69th and 101th cell positions respectively. But these values don't repeat in each cell. E.g I would like the 'v' value to show from cell 1 to cell 68, but it appears only in the first cell. As well as for the other values.
Thanks in advance for your precious help!
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Tables en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!