Combining three text files into one text file

9 views (last 30 days)
Hi,
I am a new user of MATLAB. I am trying to merge three text files (attached) into one file and add a space between each one of the three files.
I used system and join but I can not generate this file.
Many thanks in advance!

Accepted Answer

DGM
DGM on 9 Feb 2022
Since I have no idea what you tried, I'm just going to do this in MATLAB.
Note that the first and second file already have trailing empty lines. I'm going to trim those so that there is only one empty line between each chunk of text. This obviously means that this is not a general solution.
A = fileread('1.txt');
B = fileread('2.txt');
C = fileread('3.txt');
fid = fopen('out.txt','w');
fprintf(fid,'%s',[A(1:end-2) B C]);
fclose(fid);
The result is:
nName,nodesC1,nodesC2,nodesC3,nType
n111,0,0,0,structural
n111-y1,0,450,0,structural
n111-y2,0,1500,0,structural
n111-y3,0,2550,0,structural
n121,0,3000,0,structural
n121-x1,600,3000,0,structural
eL,eTy,eSN,eEN,eT
elm.name, grp.name, nod.name(s), mass121, mass1
mass131, mass1, n131, mass141, mass1
mass221, mass2, n221, mass231, mass2
mass241, mass2, n241, mass321, mass1
mass331, mass1, n331, mass341, mass1
col1111, col, n111, n111-y1, nsn1001
resN,resC
nod.name, direction
n111, x+y+z+rx+ry+rz
n111-y1, z+rx+ry
n111-y2, z+rx+ry
n111-y3, z+rx+ry

More Answers (0)

Categories

Find more on Characters and Strings in Help Center and File Exchange

Tags

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!