Find data from txt file
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Hi all,
I try to find a data from txt file. In a row (i don't known which row), there is an information like "Dt: 0.0001". I want to find this row and store 0.0001 as a variable. How can i do that?
Thanks for help
Risposte (2)
Mathieu NOE
il 30 Apr 2024
Simply using the suggested methods , you can access your DT data this way
I simply created two data files from you post
I used lower to convert all characters to lower case which then ease the process
% first file
out = fileread('data1.txt')
str = extractBetween(lower(out),'dt','sec');
A = regexp(str,'[-+]?([0-9]*[.])?[0-9]+([eE][-+]?\d+)?','match'); % extract numerical content of string
dt_value = str2double(A{1})
% second file
out = fileread('data2.txt')
str = extractBetween(lower(out),'dt','sec');
A = regexp(str,'[-+]?([0-9]*[.])?[0-9]+([eE][-+]?\d+)?','match'); % extract numerical content of string
dt_value = str2double(A{1})
3 Commenti
Vedere anche
Categorie
Scopri di più su Data Type Conversion in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!