필터 지우기
필터 지우기

Trouble importing data file

조회 수: 4 (최근 30일)
David Maréchal
David Maréchal 2019년 12월 27일
댓글: David Maréchal 2020년 1월 28일
I have trouble to import the following file (File_minimum_example.txt, enclosed here) as table (or array), using Matlab R2018a.
  • When using uiimport, I obtain the message "File Encoding UTF16-LE is not supported. [...]" and I can't see my data.
  • When using importdata, I obtain only one column instead of 11. Plus, one empty row separates every consecutive rows, probably due to the fact my data file uses two delimiters: ";" and "\n".
  • When using readtable, I use the code below:
T = readtable(filename, 'Format','%f%f%f%f%f%f%f%f%f%f%f', 'Delimiter', ';');
but I obtain an error message "Unable to read the entire file. You may need to specify a different format, delimiter, or number of header lines." Possibly because I can't work out how to remove the first row, which is useless, but which will be systematically present in all the files I'd like to treat.
Could you advise me on how to best import all these data (including headers that appear on row #2) ? Many thanks in advance,

채택된 답변

Patrick Gipper
Patrick Gipper 2019년 12월 30일
Open the file using Word. Word will recognize that it is a non-standard text format and default to Unicode. Then simply save the file using File/Save As. A File Conversion box will pop up. Make sure you select MS-DOS for the Text Encoding. The new file can now be recognized using the Matlab command readtable. You can probably create a Word macro to automate the conversion.
  댓글 수: 4
Guillaume
Guillaume 2020년 1월 28일
Note that by converting a file from UTF16 to ANSI or MS-DOS you may irreversibly replace some characters with an 'unknown character symbol'. UTF16 supports significantly more charactes (137,994 as of this comment) than MS-DOS or ANSI (127 or 256).
Converting to UTF8 instead would ensure that all characters are preserved.
David Maréchal
David Maréchal 2020년 1월 28일
Dear Guillaume,
I used a converter to transform my UTF16 data file to UTF8. I saved it, then opened it in Matlab, using the command uiimport. It works fine too. Many thanks for this solution that preserves more characters.
David

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 String Parsing에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by