我有三个txt文件
未排序文件: s1.txt s2.txt s3.txt
我应该怎样才能以这种格式在新的txt文件中得到输出?
你是否可以使用这种格式,而非之前的格式?
s1.txt,s2.txt,s3.txt
。它们的格式和数据数量都相同。我想将这三个文件中的第二列合并到一个文件中。在合并数据之前,我按照第一列对其进行了排序:未排序文件: s1.txt s2.txt s3.txt
1 23 2 33 3 22
4 32 4 32 2 11
5 22 1 10 5 28
2 55 8 11 7 11
已排序文件: s1.txt s2.txt s3.txt
1 23 1 10 2 11
2 55 2 33 3 22
4 32 4 32 5 28
5 22 8 11 7 11
以下是我目前的代码:
BaseFile ='s'
n=3
fid=fopen('RT.txt','w');
for i=1:n
%Open each file consecutively
d(i)=fopen([BaseFile num2str(i)'.txt']);
%read data from file
A=textscan(d(i),'%f%f')
a=A{1}
b=A{2}
ab=[a,b];
%sort the data according to the 1st column
B=sortrows(ab,1);
%delete the 1st column after being sorted
B(:,1)=[]
%write to a new file
fprintf(fid,'%d\n',B');
%close (d(i));
end
fclose(fid);
我应该怎样才能以这种格式在新的txt文件中得到输出?
23 10 11
55 33 22
32 32 28
22 11 11
你是否可以使用这种格式,而非之前的格式?
23
55
32
22
10
33
32
11
11
22
28
11
B = A {:};
。 - yuk