Removing numerical data from txt file
Mostrar comentarios más antiguos
Inport a txt file, and remove all numerical data, have only text left. when importing text file, the text gets surrounded by quotes.
Respuestas (3)
Sulaymon Eshkabilov
el 18 de Feb. de 2023
Editada: Sulaymon Eshkabilov
el 18 de Feb. de 2023
Here is one of the possible solutions for this exercise regexprep():
Text=readlines('Citation.txt') % Read data file with texts and numbers
A = regexprep(Text, '\d+(?:_(?=\d))?', '') % All numbers removed
(2) another data file:
Atext=readlines('DATA_TEXT.txt')
A = regexprep(Atext, '\d+(?:_(?=\d))?', '')
3 comentarios
Sophia Starzynski
el 20 de Feb. de 2023
Sulaymon Eshkabilov
el 20 de Feb. de 2023
Please shart your text or dat file to give a proper solution or guidance.
Sophia Starzynski
el 20 de Feb. de 2023
Sulaymon Eshkabilov
el 20 de Feb. de 2023
Editada: Sulaymon Eshkabilov
el 20 de Feb. de 2023
Here is the solution:
unzip('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1300600/CONTROLDS2247_SGI_PPCS_Battery_1142022_1218PM_Splice.zip')
A = readlines('CONTROLDS2247_SGI_PPCS_Battery_1142022_1218PM_Splice.txt');
Bnum = regexp(A,'\d*','Match'); % Only numbers
Ctxt = regexprep(A, '\d+(?:_(?=\d))?', ''); % Only texts taken out
% Empty cells are cleaned up
Index1 = (Ctxt(1:end,:)=='-.');
Ctxt(Index1,:)=[];
Index2 = (Ctxt(1:end,:)=='.');
Ctxt(Index2,:)=[] % Only text strings are stored and all empty cells are removed
% Write the cleaned strings into MS Excel
xlswrite('OUT.xlsx', Ctxt)
1 comentario
Sophia Starzynski
el 20 de Feb. de 2023
Here is the solution to keep the time of data collected in the external file:
unzip('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1300600/CONTROLDS2247_SGI_PPCS_Battery_1142022_1218PM_Splice.zip')
A = readlines('CONTROLDS2247_SGI_PPCS_Battery_1142022_1218PM_Splice.txt');
Bnum = regexp(A,'\d*','Match'); % Only numbers
Ctxt = regexprep(A, '\d+(?:_(?=\d))?', ''); % Only texts taken out
% Keep the dates:
Index0 = Ctxt(1:end, :)=='// :: PM';
Ctxt(Index0,:) = A(Index0,:);
% Empty cells are cleaned up:
Index1 = (Ctxt(1:end,:)=='-.');
Ctxt(Index1,:)=[];
Index2 = (Ctxt(1:end,:)=='.');
Ctxt(Index2,:)=[]
% Cleaned data is stored in an external file
xlswrite('OUT.xlsx', Ctxt)
1 comentario
Sulaymon Eshkabilov
el 20 de Feb. de 2023
The answer solution is acceptable :)
Categorías
Más información sobre Environment and Settings en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!