Creating a file from different-sized files.
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Nada
le 22 Fév 2023
Réponse apportée : William Rose
le 22 Fév 2023
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 commentaire
Anton Kogios
le 22 Fév 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.
Réponse acceptée
William Rose
le 22 Fév 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 commentaires
Plus de réponses (1)
Kevin Holly
le 22 Fév 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 commentaires
Voir également
Catégories
En savoir plus sur Text Data Preparation dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!