Creating a file from different-sized files.

2 Ansichten (letzte 30 Tage)
Nada
Nada am 22 Feb. 2023
Beantwortet: William Rose am 22 Feb. 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 Kommentar
Anton Kogios
Anton Kogios am 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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

William Rose
William Rose am 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))
Size of Data=20709 x 9.
fprintf('Size of A.data=%d x %d.',size(A.data))
Size of A.data=8536 x 9.
fprintf('Size of DataAll=%d x %d.',size(DataAll))
Size of DataAll=29245 x 9.
save('DataAll.txt','DataAll','-ascii') %save combined data to text file
Try it. Good luck.

Weitere Antworten (1)

Kevin Holly
Kevin Holly am 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')
TT = 8536×9 table
Pressdbar SVms Rpos SALINppt CAP25mScm TempC PAH CH4 TR1 _________ ______ ______ ________ _________ ______ ______ ______ ______ 0.1672 1540.4 26.621 39.142 26.621 26.621 39.142 26.621 26.621 0.3344 1540.4 26.612 39.15 26.612 26.612 39.15 26.612 26.612 0.5016 1540.4 26.625 39.146 26.625 26.625 39.146 26.625 26.625 0.6687 1538.1 26.611 39.165 26.611 26.611 39.165 26.611 26.611 1.0031 1539 26.617 39.17 26.617 26.617 39.17 26.617 26.617 1.1703 1540.4 26.629 39.174 26.629 26.629 39.174 26.629 26.629 1.3375 1540.4 26.624 39.169 26.624 26.624 39.169 26.624 26.624 1.5047 1540.4 26.633 39.169 26.633 26.633 39.169 26.633 26.633 1.6719 1540.5 26.63 39.171 26.63 26.63 39.171 26.63 26.63 2.0062 1540.5 26.633 39.178 26.633 26.633 39.178 26.633 26.633 2.1734 1540.5 26.631 39.161 26.631 26.631 39.161 26.631 26.631 2.3406 1540.5 26.635 39.164 26.635 26.635 39.164 26.635 26.635 2.675 1540.5 26.634 39.15 26.634 26.634 39.15 26.634 26.634 2.8422 1540.5 26.631 39.161 26.631 26.631 39.161 26.631 26.631 3.0093 1540.5 26.634 39.157 26.634 26.634 39.157 26.634 26.634 3.1765 1540.5 26.63 39.156 26.63 26.63 39.156 26.63 26.63
writetable(TT,'now_file','FileType','text')
Line_2 = table2array(Line_2)
Line_2 = 2×1 cell array
{'09 02 2011 05:57:36'} {'21 37.061 38 59.139'}
fid = fopen('now_file.txt', 'a+');
fprintf(fid, Line_2{1});
fprintf(fid, Line_2{2});
fclose(fid);

Kategorien

Mehr zu Low-Level File I/O finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by