Removing numerical data from txt file
Afficher commentaires plus anciens
Inport a txt file, and remove all numerical data, have only text left. when importing text file, the text gets surrounded by quotes.
Réponses (3)
Sulaymon Eshkabilov
le 18 Fév 2023
Modifié(e) : Sulaymon Eshkabilov
le 18 Fév 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 commentaires
Sophia Starzynski
le 20 Fév 2023
Sulaymon Eshkabilov
le 20 Fév 2023
Please shart your text or dat file to give a proper solution or guidance.
Sophia Starzynski
le 20 Fév 2023
Sulaymon Eshkabilov
le 20 Fév 2023
Modifié(e) : Sulaymon Eshkabilov
le 20 Fév 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 commentaire
Sophia Starzynski
le 20 Fév 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 commentaire
Sulaymon Eshkabilov
le 20 Fév 2023
The answer solution is acceptable :)
Catégories
En savoir plus sur Environment and Settings dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!