Creating a file from different-sized files.
1 次查看(过去 30 天)
显示 更早的评论
Hi to all
I have these files consisting of two variabilities, so I want to create one formatted text file
start from the Line_2.mat, it will be the four rows of a now_file, then from the second file TT.txt, I want to add the table to now_file.
1 个评论
Anton Kogios
2023-2-22
Which variable in Line_2.mat are you talking about? And have you made an attempt at solving this? If so, post your code.
采纳的回答
William Rose
2023-2-22
Line_2.mat contains several variables. Let's assume you are interested in the one called Data. To append the data in TT.txt, do the following:
load('Line_2.mat'); % loads all the data in Line_2.mat
A=importdata('TT.txt'); % structure A contains the headers and the data
DataAll=[Data;A.data]; % combine
fprintf('Size of Data=%d x %d.',size(Data))
fprintf('Size of A.data=%d x %d.',size(A.data))
fprintf('Size of DataAll=%d x %d.',size(DataAll))
save('DataAll.txt','DataAll','-ascii') %save combined data to text file
Try it. Good luck.
0 个评论
更多回答(1 个)
Kevin Holly
2023-2-22
Did you want something like this? Note, I attached an import function called importTTfile.
load('Line_2.mat')
TT = importTTfile('TT.txt')
writetable(TT,'now_file','FileType','text')
Line_2 = table2array(Line_2)
fid = fopen('now_file.txt', 'a+');
fprintf(fid, Line_2{1});
fprintf(fid, Line_2{2});
fclose(fid);
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Whos 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!