Read a string from text file returning strange characters
9 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
Geoff Hayes
2014 年 8 月 2 日
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?
採用された回答
per isakson
2014 年 8 月 2 日
編集済み: per isakson
2014 年 8 月 2 日
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
その他の回答 (1 件)
John
2014 年 8 月 3 日
Play around with the EncodingIn key value pair for the fopen function. Chances are its opened in the wrong encoding mode.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Text Files についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!