Clear Filters
Clear Filters

How can I automatically import different variables from txt files and split them in different matrixes?

3 views (last 30 days)
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

Answers (1)

dpb
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.

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!