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 commentaire

Rik
Rik le 25 Juil 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.

Connectez-vous pour commenter.

Réponses (1)

Star Strider
Star Strider le 25 Juil 2020

0 votes

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

Catégories

Question posée :

le 25 Juil 2020

Commenté :

Rik
le 25 Juil 2020

Community Treasure Hunt

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

Start Hunting!

Translated by