필터 지우기
필터 지우기

import data from txt missing delimiters

조회 수: 5 (최근 30일)
Christian von Spreckelsen
Christian von Spreckelsen 2016년 5월 22일
댓글: Todd Leonhardt 2016년 5월 22일
I am struggeling with importing data from a .txt file in my script, and i believe it is due to a '$' in my first coloumn. I have tried using csvread, textscan and importdata. The only thing i got to work was importdata, but it ignores the delimiters.
This is the command i use: "test = importdata(fullpathname,',')"
It gives me a 1291x1 array, which should have been a 1291x10.
I have attached the file im trying to import. Anyone got an idea how to import the data in different coloumns?
Thanks!

채택된 답변

Todd Leonhardt
Todd Leonhardt 2016년 5월 22일
Have you tried the readtable() command yet? http://www.mathworks.com/help/matlab/ref/readtable.html
It works very well with delimited files. It also allows you to specify an optional 'Format' if it doesn't work correctly out of the box.
  댓글 수: 3
Christian von Spreckelsen
Christian von Spreckelsen 2016년 5월 22일
I got a little problem with the format. I am trying to get the numbers from my data alone, but when i use "T = readtable(fullpathname,'Delimiter',',','ReadVariableNames',false,'Format','%n%n%n%n%n%n%n%n%n%n')" i get the following message: "Error using readtable (line 135) Unable to read the entire file. You may need to specify a different format string, delimiter, or number of header lines.
Caused by: Reading failed at line 1. A field on that line may have contained the wrong type of value."
If i leave out Format there is no problem, but as soon as i insert Format it goes wrong. Any idea what is wrong?
Todd Leonhardt
Todd Leonhardt 2016년 5월 22일
For the format string, try something like:
'$%n%n%n%n%n%n%n%n%n%n#'
And since all of your numbers look like integers, maybe consider replace the "%n" which signifies a double precision float with %u for unsigned integer or %d for signed integer.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by