Read a string from text file returning strange characters

5 visualizaciones (últimos 30 días)
Jack
Jack el 2 de Ag. de 2014
Comentada: Noam Greenboim el 21 de Mayo de 2020
I'm reading a string like "1.0.2" from text file with these codes :
reader = fopen('Address\My_Text.txt');
Out= textscan(reader,'%str');
Out1=Out{1} ;
Out2=Out1{1};
fclose(reader);
This code (Out2) returns a string like this: "1.0.2" . This is a text file that copied by MATLAB from other place in HDD (The main file is working correctly). When I create a text file manually, insert "1.0.2" in it, These codes read this value correctly. What is the problem? What is the solution for MATLAB?
Thanks.
  2 comentarios
Geoff Hayes
Geoff Hayes el 2 de Ag. de 2014
Jack - what do you mean by text file that copied by MATLAB from other place in HDD? Do you mean that you have some MATLAB code that copied the file? If so, what does that code look like?
Jack
Jack el 2 de Ag. de 2014
Editada: Jack el 2 de Ag. de 2014
My code is downloading a text file from FTP server. after that compare it with containing of other file and at last replace it with that file by movefile, so only I read it ( with above codes ) and copy it with movefile. In last phase I want read it again and have this problem.

Iniciar sesión para comentar.

Respuesta aceptada

per isakson
per isakson el 2 de Ag. de 2014
Editada: per isakson el 2 de Ag. de 2014
I guess that you see a "problem" with the encoding of your file. I guess it's UTF-8 and that "" is a distorted BOM-character. What is the encoding? Try open the file with Excel to let Excel guess.
See

Más respuestas (1)

John
John el 3 de Ag. de 2014
Play around with the EncodingIn key value pair for the fopen function. Chances are its opened in the wrong encoding mode.

Categorías

Más información sobre Data Import and Export en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by