Error reading text file using readtable

조회 수: 3 (최근 30일)
Laila
Laila 2015년 3월 13일
댓글: Brendan Hamm 2015년 3월 13일
Hi,
I have a table (store in file.txt) of the form:
cats 1 2 3 4 5
dogs 6 7 8 9 0
chickens 3 4 5 6 1
Basically, a text file with row names followed by space separated integers. However when I try:
T=readtable('file.txt','Delimiter',' ')
I get the following error:
Error using table/readTextFile (line 250)
Variable lengths must all be the same.
However each line in (T) is the same length! I have tried this with other files of the same format and it has worked.
I did try dlmread, however because the file has mixed types, this also does not work.
Any suggestions?
  댓글 수: 1
Brendan Hamm
Brendan Hamm 2015년 3월 13일
If you could attach the .txt file that would be helpful.

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

답변 (1개)

Peter Perkins
Peter Perkins 2015년 3월 13일
This
T=readtable('file.txt',' ',[0 1])
is not the correct way to call readtable. I have no idea what [0 1] is intended to be, but I assume that ' ' is intended to be the delimiter. Try this:
T=readtable('file.txt','Delimiter',' ')
and check the documentation for more details. Hope this helps.
  댓글 수: 1
Laila
Laila 2015년 3월 13일
sorry that was a typo, have edited the question.

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

카테고리

Help CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by