Edit Textfile for analysis
Ältere Kommentare anzeigen
Hi, I here by attached text file. I want the text file to be read as the following manner. Any help would be appreciated. Thank you
*Heading
** Job name: Job-1 Model name: Model-1
** Generated by: Abaqus/CAE 6.14-5
*Preprint, echo=NO, model=NO, history=NO, contact=NO
**
** PARTS
**
*Part, name=rect
*Node
1, -0.375, -0.125
2, -0.427631587, -0.125
3, -0.480263144, -0.125
*Element, type=CPS4
1, 1, 2, 22, 21
2, 2, 3, 23, 22
3, 3, 4, 24, 23
4, 4, 5, 25, 24
*End Part
**
2 Kommentare
Mathieu NOE
am 13 Jan. 2021
hi
you can use readlines :
readlines('file.txt')
RAKESH KUMAR TOTA
am 13 Jan. 2021
Bearbeitet: Rik
am 13 Jan. 2021
Akzeptierte Antwort
Weitere Antworten (1)
Mathieu NOE
am 13 Jan. 2021
ok
so my 2 cent suggestion to make that array looks nicer -
lines = readlines('aba.txt','WhitespaceRule','trim');
ll_out = strings; % init string array
for ci = 1:numel(lines)
ll = lines(ci,:); % current line
if ~startsWith(ll,'*'); % check lines 10 to 20 - here we have to work things out
lldk = strrep(ll,' ',''); % remove all (multiple) blanks inside the char array
ll_out(ci,1) = strrep(lldk,',',', '); % put back one blank after the comma (if really needed)
else % nothing to do except copy the original line
ll_out(ci,1) = ll;
end
end
% save it - and remove the double quote
writematrix(ll_out, 'test.txt',"QuoteStrings",0)
1 Kommentar
RAKESH KUMAR TOTA
am 18 Jan. 2021
Kategorien
Mehr zu Text Files finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!