Find data from txt file
이전 댓글 표시
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
댓글 수: 5
Akira Agata
2024년 4월 29일
How about using startsWith (to detect "DT:") + split (to split "DT" and data) + str2double (to covert to double)?
KSSV
2024년 4월 30일
Attach your text file.
Cem Eren Aslan
2024년 4월 30일
Stephen23
2024년 4월 30일
답변 (2개)
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
Mathieu NOE
2024년 5월 28일
hello again
problem solved ?
Cem Eren Aslan
2024년 5월 29일
Voss
2024년 5월 29일
@Cem Eren Aslan: What solution did AI give you?
카테고리
도움말 센터 및 File Exchange에서 String Parsing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!