array2table won't accept variable name input
Mostrar comentarios más antiguos
I am attempting to turn an array into a table before I output it into a file, and I am running into an error when I attempt to try and put variable names into my table.
data = randi(100,10,5);
headers = {'T','1','2','3','4'};
tabl = array2table(data,'VariableNames',headers);
Error using array2table (line 62)
'1' is not a valid variable name.
Error in TestCode (line 3)
tabl = array2table(data,'VariableNames',headers);
I don't understand why '1' is not a valid variable name. Can I not use numbers, even when they're a string? I have confirmed the class is 'char' for the actual contents of the headers cell, but it still doesn't seem to like it.
Respuesta aceptada
Más respuestas (1)
Sean de Wolski
el 24 de Mzo. de 2021
Editada: Sean de Wolski
el 24 de Mzo. de 2021
0 votos
Support for invalid variable names was added recently so you're probably on an older release that required >>isvarname(varname) to be true.
You can
- upgrade
- call: matlab.lang.makeValidName to turn your names valie
- Change the names to valid yourself "One", "Two" would be valid...
1 comentario
Bob Thompson
el 24 de Mzo. de 2021
Categorías
Más información sobre LaTeX 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!