更改一个文本文件,数字和文本
4视图(30天)
显示旧的评论
答案(1)
鸡向量
2023年4月27日
编辑:鸡向量
2023年4月27日
str = fileread (“hector_400km.txt”);
行= regexp (str,“| | \ r \ n \ r \ n”,“分裂”);
为= 20行:长度(线)
modifiedData = str2num({线}行)* 0.89;
%完成这张支票,因为我注意到一些线路(例如620)没有数据
% multplied:
如果~ isempty (modifiedData)
nSpaces = 6 -元素个数(num2str(地板(modifiedData (1))));
行{线}= [repmat (' '1,nSpaces) num2str (modifiedData' % 9.2 f '));
结束
结束
fid = fopen (“hector_400km_new.txt”,' w ');
流(fid检测器,“% s \ n”{:}行);
文件关闭(fid);
这应该保留空间和格式化,否则,如果你不在乎代码可以简化,您可以编写一个. csv
writecell
。