Creating a file from different-sized files.
2 ビュー (過去 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 で Low-Level File I/O についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!