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

3 次查看(过去 30 天)
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 个)

dpb
dpb 2017-1-19
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.

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by