Assinging variable names to data read from files
Show older comments
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 Comment
Rik
on 25 Jul 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.
Answers (1)
Star Strider
on 25 Jul 2020
0 votes
Use readtable (R2013b and later versions) and then define a cell array of VariableNames to use with it.
Categories
Find more on Structures in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!