필터 지우기
필터 지우기

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
Stephen23
Stephen23 2017년 1월 19일
편집: Stephen23 2017년 1월 19일
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.

댓글을 달려면 로그인하십시오.

답변 (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에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by