Labfans是一个针对大学生、工程师和科研工作者的技术社区。 论坛首页 | 联系我们(Contact Us)
MATLAB爱好者论坛-LabFans.com
返回   MATLAB爱好者论坛-LabFans.com > 其它 > 资料存档
资料存档 资料存档
 
 
主题工具 显示模式
旧 2019-12-10, 20:41   #1
poster
高级会员
 
注册日期: 2019-11-21
帖子: 3,006
声望力: 66
poster 正向着好的方向发展
帖子 MATLAB合并数据

如何将两个数据列合并到一个文件中。这些代码应产生一个新文件,其中包含2列。尽管它产生2列,但是数据不正确,因为先写入a所有数据,然后写入数据duration

fid=fopen('data1.txt'); A =textscan(fid,'%f%f%f%f%f%f%f%f%f%f%f%f'); % read a txt file in = cell2mat(A); %change to matrix fclose(fid); index = find(in(2:end,2) == in(1:end-1,2)) + 1; %condition 1 duration(index)= in(index,4) - in(index-1,4); a(index)=in(index,2); fid = fopen('test.txt','wt'); format short g; fprintf(fid,'%g\t%g\n',a,duration); fclose(fid); 编辑:输出格式如下所示-

318684 24 % 318684 I don't know where this number come from, not from the input 24 24 % this is the a output 24 24 1.1 1.08 % this is the duration output 2.1 0.77 预期的输出是

24 1.1 24 1.08 24 2.1 24 0.77 1.3 1.8

回答:

您需要修复fprintf行:

fprintf(fid,'%g\t%g\n',[a(:),duration(:)]');

更多&回答...
poster 当前离线   回复时引用此帖
 


发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛禁用 表情符号
论坛启用 [IMG] 代码
论坛启用 HTML 代码



所有时间均为北京时间。现在的时间是 01:09


Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.