How can I automatically import different variables from txt files and split them in different matrixes?
2 views (last 30 days)
Show older comments
I have got multiple text files containing 5 columns each. All columns are 101 points long. Each column is a variable (v1,v2,v3,v4,v5). I want to import each variable in independent matrixes. At the end I want a matrix made of all the v1, another matrix made of all the v2, and so on.
What I have done is to individually import data from each text file, split the columns in individual variables and then concatenate all the v1s together, all the v2s together, and so on.
There have to be a way to create empty matrixes, then have Matlab to fill those matrixes with specific columns while is importing the data. maybe through a loop to read the files, and a loop to import individual columns?
Anybody can help me?
thanks
1 Comment
Answers (1)
dpb
on 19 Jan 2017
Yeah, but I'd strongly recommend against using so many variables in lieu of either just a NxM array or a table. When folks start writing variables with the same root name and attaching numbers or letters it's a sure sign they're (almost) always barking up the wrong tree in Matlab coding efficiency...
As for reading the multiple files, see the FAQ at <How_can_I_process_a_sequence_of_files.> The dir solution is particularly powerful and easy.
0 Comments
See Also
Categories
Find more on Data Type Conversion 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!