%读
fid = fopen('C:/words.txt','r');
txt = textscan(fid,'%s');
fclose(fid);
%解决中文乱码问题(法一)【TXT文件默认“ANSI”编码,转成“UTF-8”编码】
encoding = 'UTF-8';
currentCharacterEncoding = slCharacterEncoding();
slCharacterEncoding(encoding) %encoding 为设置的具体的编码模式
fid = fopen('C:/words.txt','r');
txt = textscan(fid,'%s');
fclose(fid);
% 缺点:接下来整个程序都按“UTF-8”编码方式运行。
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%解决中文乱码问题(法二)【TXT文件默认“ANSI”编码,转成“UTF-8”编码】
fp = fopen('test.txt','r','n','utf-8');
s2 = fgets(fp)
% 优点:仅仅此段程序按“UTF-8”编码方式运行,其他不变。
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%写
txt = ['a' 's' 'd' 'f' 'g' 'h'];
dlmwrite('C:/myfile.txt', txt, 'delimiter', '\t')