Borrar filtros
Borrar filtros

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

3 visualizaciones (últimos 30 días)
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 comentario
Stephen23
Stephen23 el 19 de En. de 2017
Editada: Stephen23 el 19 de En. de 2017
There is a way, but you really really don't want to do this. Read this to know why it is a really bad idea to generate variables in a loop:
Learn to write efficient code: use indices.

Iniciar sesión para comentar.

Respuestas (1)

dpb
dpb el 19 de En. de 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.

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by