Hello, I've searched in many discussions and didn't find a solution for my problem. I have got a textfile with some headlines and afterwards there are data. It's like Pos1 Pos2 Pos3 ... 1.2 2.3 2.13 ... 4.23 2.34 2.22 ... 7.54 4.55 2.55 ... ... I want to import the files but the number of columns differs. And the number of lines ist about 20.000 so I need a code, that reads automatically until the end of the columns and lines. Is there any solution? Unfortunately, i'm a very beginner and I haven't done much with Matlab. I'e tried a lot with textscan function but I wasn't successful.. Thanks in advance!

댓글 수: 2

Stephen23
Stephen23 2016년 5월 6일
Please edit your question and upload a sample file using the paperclip button. A sample file does not to be all of the data, but it needs to correctly represent the structure of the complete data file.
Jan
Jan 2016년 5월 6일
How can the "some headlines" be recognized? Please post a copy of teh relevant part of the file. Note that "it's like..." is not exact enough to post matching code.

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

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2016년 5월 6일

0 개 추천

You can use importdata
D=importdata('fileName.txt')
N=D.data

댓글 수: 1

ThermoSteel
ThermoSteel 2016년 5월 11일
Thanks for the answer. I can use it for my data import!

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

추가 답변 (1개)

Jan
Jan 2016년 5월 6일

0 개 추천

Open the file by fopen. Then read it line by line until you read the first line of data. I cannot guess how this is recognized, because this might depend on the header lines.
Then read the first line of data. Use sscanf(LineStr, '%g') to determine the number of columns. Now adjust the format string to teh number of columns and import the rest of the file by fscanf.
A more explicit answer is possible, if you who us a typical file.

카테고리

도움말 센터File Exchange에서 Deep Learning Toolbox에 대해 자세히 알아보기

질문:

2016년 5월 6일

댓글:

2016년 5월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by