part txt file combine first two line into one line and repeat for the following next two lines.
3 views (last 30 days)
Show older comments
Hello everyone, I have a part file like this
and would like to combine the first two line into one line then repeat for the next following lines, I tried reshape tool and seperating it into lines but no luck. would like to organize the data back into an organized excel file row by row.
% Get the individual lines - step 2
line1 = data{1}{1}; % Assuming the first line contains the first set of data
line2 = data{1}{2}; % Assuming the second line contains the second set of data
s = strcat(line1,line2)
%creating a repeating loop for next 2 lines of data.
x = split(s,",");
0 Comments
Answers (1)
dpb
on 21 Jun 2023
txt=[
"2223343 MATERIAL: UNKNOWN "
"1.22222e-06 1.33333e+02 1.44444e+03 5.55555e+00 -4.66666e+00"
"2222855 MATERIAL: UNKNOWN "
"2.77777e-06 2.88888e+02 1.99999e+03 -3.57777e+00 -1.98888e+01"
"2222444 MATERIAL: UNKNOWN "
"2.83333e-06 2.42228e+02 6.73333e+02 7.11111e+00 1.24444e+00"];
writematrix(txt,'temp.txt')
OK, now we've created a sample file; let's fix it as desired...we'll use newer high level string array here...
txt=readlines('temp.txt');
txt=txt(strlength(txt)>0); % remove any trailing null line
txt=strcat(txt(1:2:end), txt(2:2:end))
0 Comments
See Also
Categories
Find more on Text Files 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!