标签:
matlab中文乱码 |
分类: Matlab编程 |
现象:
解决方法:
测试文件一:
----------------
%
test_fgetl1.m 测试fgetl函数
%
中文为什么读出来是乱码
fid = fopen('test_fgetl1.m');
while 1
tline =
fgetl(fid);
if
~ischar(tline),
break, end
disp(tline)
end
fclose(fid);
%
fid = fopen('test_fgetl1.m');
while 1
end
fclose(fid);
-----------------
现象:
中文部分显示为乱码。
测试文件二:
----------------
%
test_fgetl2.m 测试fgetl函数
%
中文为什么读出来是乱码
fid = fopen('test_fgetl2.m');
while 1
tline =
native2unicode(fgetl(fid));
%
fid = fopen('test_fgetl2.m');
while 1
end
fclose(fid);
-----------------
现象:
中文部分显示正常,但出现无限循环。
原因:
估计native2unicode函数将文件结束符也转换成字符了。
测试文件三:
----------------
%
test_fgetl3.m 测试fgetl函数
%
中文为什么读出来是乱码
fid = fopen('test_fgetl3.m');
while 1
tline =
fgetl(fid);
%
fid = fopen('test_fgetl3.m');
while 1
end
fclose(fid);
-----------------
现象:
中文显示正常,文件可以正常读完。

加载中…