Assinging variable names to data read from files

Hello,
I am imporing tables of data from files and would like to automaticaly name the variables into which I assign the data so I can use it later for analysis.
When I use Live Editor to generate a script to import the data a unique variable name is used but the variable name is generated from the file name which is not good for me.
I can create the variable names using srtcat() or sprintf() but get an error when I try to assign the data.
Thanks

1 comentario

Rik
Rik el 25 de Jul. de 2020
The solution is simple: don't use automatically generated variable names. Metadata (such as the source file) is data itself. Store it as such. You can use a struct array with one field containing the source file name and another field containing the data itself.
Using arrays will allow you to easily manipulate your data and use loops and built-in operations on your data.

Iniciar sesión para comentar.

Respuestas (1)

Star Strider
Star Strider el 25 de Jul. de 2020

0 votos

Use readtable (R2013b and later versions) and then define a cell array of VariableNames to use with it.

Categorías

Etiquetas

Preguntada:

el 25 de Jul. de 2020

Comentada:

Rik
el 25 de Jul. de 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by