Creating a file from different-sized files.
1 view (last 30 days)
Show older comments
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 Comment
Anton Kogios
on 22 Feb 2023
Which variable in Line_2.mat are you talking about? And have you made an attempt at solving this? If so, post your code.
Accepted Answer
William Rose
on 22 Feb 2023
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 Comments
More Answers (1)
Kevin Holly
on 22 Feb 2023
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 Comments
See Also
Categories
Find more on Whos in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!