Read the Text File in matlab

Sir,
I read the text file using
filename='E:\outpo.txt';
x=textread(filename,'%s');
The output file contains some symbols. eg,  english
But their is no symbols in the input file.
why it comes?

답변 (2개)

David Sanchez
David Sanchez 2013년 12월 11일

0 개 추천

What's the contents of the original file? The output will depend on the coding of the original file. Were all the characters in the original file standard ones ( ASCII )? Anyway, read carefully the documentation of textread:
doc textread
You'll be tipped with several examples worth testing.
Walter Roberson
Walter Roberson 2013년 12월 11일

0 개 추천

If you are seeing those particular characters then your file is UTF encoded. I do not recall at the moment whether it is UTF-8 or UTF-16 that uses that exact sequence.
Remember that %s format reads a string at a time, and strings are terminated by whitespace. Are you trying to split it up into words or split it up into lines?
filename='E:\outpo.txt';
x = regexp( fileread(filename), '\n', 'split'); %read it and break it into lines.

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

질문:

2013년 12월 11일

편집:

2013년 12월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by