Cell Array of Strings Indexing and Relabeling to Numeric Values?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Erin Winkler
el 18 de Jul. de 2018
Respondida: dpb
el 18 de Jul. de 2018
Hi all,
I have a cell array of strings that mark certain sites (example: 'Townsville - Crossroad Station (1234)'). I have 27 different sites in total.
What I need help with is, this is a column in a table with other data and I wanted to change the strings to numbers.
Something like this:
if site(i) == 'Townsville - Crossroads Station (1234)'
site(i) = 0;
if site(i) == 'City Colonies - Fork in Road (5678)'
site(i) = 1;
.
.
.
else
site(i) = 26;
I want this so I can then make subset matrices of values from the table filtered by the condition without typing a huge string each time. I could also then treat it as categorical data as a factor more easily.
Or, if it's possible to do this, if there is a way to loop through and set a string = number (like above) but index the number it sets each time the string is different, that would be great too.
The main components of the table I'm evaluating are: datetimes, site, day of week
right now and I want to section off by site first.
Any help would be great, thank you!
0 comentarios
Respuesta aceptada
dpb
el 18 de Jul. de 2018
This is perfect use for categorical variable...and to use a |table instead of cell array for the data structure. Life will be much easier then... :)
Attach a .mat file with your input file and someone here can (and probably will) get you quite a ways along very quickly...
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Categorical Arrays en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!